J-phage war
Time limit:1000 msMemory limit:32768kb64bit Io format:% I64d & % i64u
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 shoshould 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 wocould 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: 11
Case 2: 14 This is a naked greed. I don't know why. Today's thinking is very bad and I feel like I am not in any status. I have discussed this question with my teammates for a long time, at first, our greedy ideas were almost completely different. Because we had not yet developed a tacit understanding with our teammates, we could not achieve a good unification in the direction, but we were finally met by our teammates, it has successfully prevented us from breaking the pace, so we can reflect on ourselves. As a leader, we must take good care of everyone's ideas...
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 using namespace std; 5 const int MAXN = 100010; 6 struct node{ 7 int d,t; 8 }; 9 bool cmp(const node& a,const node& b){10 return a.t > b.t;11 }12 node bug[MAXN];13 int main()14 {15 int t,n,cas = 1;16 cin>>t;17 while(t--){18 scanf("%d",&n);19 for(int i = 1;i <= n;i++)20 scanf("%d%d",&bug[i].d,&bug[i].t);21 sort(bug + 1,bug + 1 + n,cmp);22 int ans = 0,tmp,acum = 0;23 for(int i = 1;i <= n;i++){24 tmp = bug[i].d + bug[i].t + acum;25 if(ans < tmp) ans = tmp;26 acum += bug[i].d;27 }28 printf("Case %d: %d\n",cas++,ans);29 }30 return 0;31 }
HDU 4070 + naked greedy ~~