HDU 4070 + 赤裸裸的贪心~~

                          J - Phage War

        Time Limit:1000MS     Memory Limit:32768KB     64bit 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 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

  这是一道赤裸裸的贪心,,,不知为何,今天的思维非常的差感觉都没什么状态,,和队友讨论了很久这道题,起初我们的贪心的想法几乎完全不同,由于还没有和队友培养好默契,从而没有办法很好地在方向上得到一个统一,不过最终还是被队友AC了,成功地防止了我们爆零的节奏,,,,以此反省自己,作为队长一定要好好兼顾好每个人的想法。。。

 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 }
时间: 2024-12-21 03:55:39

HDU 4070 + 赤裸裸的贪心~~的相关文章

hdu 4296 Buildings(贪心)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4296 Buildings Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1822    Accepted Submission(s): 722 Problem Description Have you ever heard the sto

hdu 4864 Task (贪心)

# include <stdio.h> # include <algorithm> # include <string.h> using namespace std; struct node { int t; int v; int yy; }; struct node a[100010],b[100010]; bool cmp(node a1,node a2) { if(a1.t==a2.t)//先按时间从大到小 return a1.v>a2.v;//再按水平从大

HDU 5014 Number Sequence 贪心 2014 ACM/ICPC Asia Regional Xi&#39;an Online

尽可能凑2^x-1 #include <cstdio> #include <cstring> const int N = 100005; int a[N], p[N]; int init(int x) { int cnt = 0; while(x > 1) { x /= 2; cnt ++; } return cnt + 1; } int main() { int n; while(~scanf("%d", &n)){ for(int i = 0;

HDU 4903 (模拟+贪心)

Fighting the Landlords Problem Description Fighting the Landlords is a card game which has been a heat for years in China. The game goes with the 54 poker cards for 3 players, where the “Landlord” has 20 cards and the other two (the “Farmers”) have 1

HDU 1045 Fire Net 贪心

Problem Description Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall. A blockhouse is a small castle that has four openings through wh

HDU 1338 Game Prediction 贪心

Problem Description Suppose there are M people, including you, playing a special card game. At the beginning, each player receives N cards. The pip of a card is a positive integer which is at most N*M. And there are no two cards with the same pip. Du

hdu 1009 FatMouse&#39; Trade(贪心)

题目来源:hdu 1009 FatMouse' Trade FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 54581 Accepted Submission(s): 18299 Problem Description FatMouse prepared M pounds of cat food, ready

hdu 4925 Apple Tree(贪心)

http://acm.hdu.edu.cn/showproblem.php?pid=4925 尽量让每棵苹果树周围都施肥,每次找到一个空地种上苹果树之后,使其周围的空地施肥,不再种苹果树. #include <stdio.h> #include <iostream> #include <map> #include <set> #include <list> #include <stack> #include <vector>

hdu 4915 Parenthese sequence (贪心+模拟)

题目大意: 一个序列中有左括号和右括号,还有问号,问号可以任意转换成左右括号. 问这个序列有多少种情况的转变使得这个序列变成合法的括号匹配序列. 思路分析: 首先我们分析一下,如何使得一个序列是合法的括号匹配序列. 我们很容易想到的是用栈模拟匹配过程. 当遇到左括号就进栈,当遇到右括号就让栈顶的左括号出栈. 那么在模拟的过程中,造成这个序列的不合法的原因只有当右括号来的时候,此时的栈已经为空. 这里补充一句,一旦一个序列给定,那么这里面的问号有多少变成左括号,多少变成右括号,是一定的. 看完以上