hdu 4070 Phage War “动中找定” 贪心

来源:互联网 发布:淘宝最好卖的东西 编辑:程序博客网 时间:2024/06/05 17:24

Phage War

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1148    Accepted Submission(s): 629


Problem Description
Phage War is a little flash game. In this game, we want infect all cells by the transmission and breed of phages. 
Originally, there is a cell infected by phages and this cell can breed a new phage every second. You should know that only the new born phages can inject other cells.

There are n cells around this cell, numbered from 1 to n. If there are Di phages reaching the i-th cell, the cell would be infected, and the phages journey will cost Ti seconds. To simplify it, we assume these phages will stay in this new cell and they can’t infect other cells. And the new cell cannot breed new phages and infect other cells.
Can you tell me how much time it costs to infect all cells at least? 
 

Input
In the first line there is an integer T (T <= 50), indicates the number of test cases.
In each case, the first line contains a integers N (1 <= N <= 10^5). Then there are N lines, each line contain two integers Di, Ti (1<=Di, Ti<=100).
 

Output
For each case, output the least time needed in one line.(as shown in the sample output)
 

Sample Input
222 15 621 113 10
 

Sample Output
Case 1: 11Case 2: 14
 

Source
The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest
 

Recommend
lcy   |   We have carefully selected several similar problems for you:  4069 4068 4062 4066 4065 
 
     动中找定:见注释

    
#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<cmath>#include<algorithm>#include<climits>#include<queue>#include<vector>#include<map>#include<sstream>#include<set>#include<stack>#include<utility>#pragma comment(linker, "/STACK:102400000,102400000")#define PI 3.1415926535897932384626#define eps 1e-10#define sqr(x) ((x)*(x))#define FOR0(i,n)  for(int i=0 ;i<(n) ;i++)#define FOR1(i,n)  for(int i=1 ;i<=(n) ;i++)#define FORD(i,n)  for(int i=(n) ;i>=0 ;i--)#define  lson   num<<1,le,mid#define rson    num<<1|1,mid+1,ri#define MID   int mid=(le+ri)>>1#define zero(x)((x>0? x:-x)<1e-15)#define mk    make_pair#define _f     first#define _s     secondusing namespace std;const int INF =0x3f3f3f3f;const int maxn=  100000+10  ;//const int maxm=    ;//const int INF=    ;typedef long long ll;const ll inf =1000000000000000;//1e15;//ifstream fin("input.txt");//ofstream fout("output.txt");//fin.close();//fout.close();//freopen("a.in","r",stdin);//freopen("a.out","w",stdout);//by yskysker123<span style="color:#ff0000;"></span>


/*任何时间,只能发送一个噬菌体,要把攻占所用时间最长的细胞放在最前面去感染:先不考虑攻占细胞时间问题,只考率噬菌体数量问题(每秒释放一个噬菌体)因为感染所有细胞所需释放的噬菌体数目是一定的,所以释放完这些噬菌体的时间也是一定的,设为t,在时间1到t,共有n个时刻(刚刚到达指定数目)开始攻占(一定有t)。先考虑t时刻,应把攻占所需时间最短的排在最后,这样攻占时间长的放前面,最后攻占结束时刻也会变小。整个过程的最后时刻也变短,这样最后一个细胞定了,就可以用刚才的方法考虑倒数第二个细胞,结果就是把时间最短的放在最后,依此类推。*/struct Cell{    int d;    int f;}  cell[maxn];int n;bool cmp(Cell x,Cell y){    return x.f>y.f;}int main(){   int T,kase=0;scanf("%d",&T);   while(T--)   {       scanf("%d",&n);       FOR1(i,n)       {           scanf("%d%d",&cell[i].d ,&cell[i].f);       }       sort(cell+1,cell+1+n,cmp);       int t=0,maxi=0;       for(int i=1;i<=n;i++)       {           t+=cell[i].d;           maxi=max(maxi,t+cell[i].f);       }       printf("Case %d: %d\n",++kase,maxi);   }    return 0;}



0 0
原创粉丝点击