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

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
  
  
2 2 2 1 5 6 2 1 11 3 10
 

Sample Output
  
  
Case 1: 11 Case 2: 14
 

Source
 

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     second

using 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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值