B: Best Relay Team
题目描述
Picture by Fernando Frazão/Agência Brasil, cc by You are the coach of the national athletics team and need to select which sprinters should represent your country in the 4 × 100 m relay in the upcoming championships.
As the name of the event implies, such a sprint relay consist of 4 legs, 100 meters each. One would think that the best team would simply consist of the 4 fastest 100 m runners in the nation, but there is an important detail to take into account: flying start. In the 2nd, 3rd and 4th leg, the runner is already running when the baton is handed over. This means that some runners – those that have a slow acceleration phase – can perform relatively better in a relay if they are on the 2nd,3rd or 4th leg.
You have a pool of runners to choose from. Given how fast each runner in the pool is, decide which four runners should represent your national team and which leg they should run. You are given two times for each runner – the time the runner would run the 1st leg, and the time the runner would run any of the other legs. A runner in a team can only run one leg.
As the name of the event implies, such a sprint relay consist of 4 legs, 100 meters each. One would think that the best team would simply consist of the 4 fastest 100 m runners in the nation, but there is an important detail to take into account: flying start. In the 2nd, 3rd and 4th leg, the runner is already running when the baton is handed over. This means that some runners – those that have a slow acceleration phase – can perform relatively better in a relay if they are on the 2nd,3rd or 4th leg.
You have a pool of runners to choose from. Given how fast each runner in the pool is, decide which four runners should represent your national team and which leg they should run. You are given two times for each runner – the time the runner would run the 1st leg, and the time the runner would run any of the other legs. A runner in a team can only run one leg.
输入
The first line of input contains an integer n, the number of runners to choose from (4 ≤ n ≤ 500).
Then follow n lines describing the runners. The i’th of these lines contains the name of the i’th runner, the time a i for the runner to run the 1st leg, and the time b i for the runner to run any of the other legs (8 ≤ b i ≤ a i < 20). The names consist of between 2 and 20 (inclusive) uppercase letters ‘A’-‘Z’, and no two runners have the same name. The times are given in seconds with exactly two digits after the decimal point.
Then follow n lines describing the runners. The i’th of these lines contains the name of the i’th runner, the time a i for the runner to run the 1st leg, and the time b i for the runner to run any of the other legs (8 ≤ b i ≤ a i < 20). The names consist of between 2 and 20 (inclusive) uppercase letters ‘A’-‘Z’, and no two runners have the same name. The times are given in seconds with exactly two digits after the decimal point.
输出
First, output a line containing the time of the best team. The precise formatting of the time is not important. Then output one lines containing the names of the runner you have picked for the 1st leg, in that team.
样例输入
6
ASHMEADE 9.90 8.85
BLAKE 9.69 8.72
BOLT 9.58 8.43
CARTER 9.78 8.93
FRATER 9.88 8.92
POWELL 9.72 8.61
样例输出
35.54
CARTER
#includeusing namespace std; struct node { string name; double n1; double n2; }a[505]; bool cmp(node a,node b) { return a.n2<b.n2; } int main() { int n; cin>>n; for(int i=0;i ) { cin>>a[i].name>>a[i].n1>>a[i].n2; } sort(a,a+n,cmp); string ansnm = a[0].name; double ans = INT_MAX; for(int i=0;i ) { int cnt = 1; double now = a[i].n1; for(int j=0;j ) { if(j!=i) { now += a[j].n2; cnt++; } if(cnt==4) { break; } } if(now<ans) { ansnm = a[i].name; ans = now; } } cout< endl; return 0; }
问题 G: Galactic Collegiate Programming Contest
时间限制: 2 Sec 内存限制: 128 MB提交: 179 解决: 62
[提交] [状态] [讨论版] [命题人:admin]
题目描述
One hundred years from now, in 2117, the International Collegiate Programming Contest (of which the NCPC is a part) has expanded significantly and it is now the Galactic Collegiate Programming Contest (GCPC).
This year there are n teams in the contest. The teams are numbered 1, 2, . . . , n, and your favorite team has number 1.
Like today, the score of a team is a pair of integers (a, b) where a is the number of solved problems and b is the total penalty of that team.
When a team solves a problem there is some associated penalty (not necessarily calculated in the same way as in the NCPC – the precise details are not important in this problem). The total penalty of a team is the sum of the penalties for the solved problems of the team.
Consider two teams t 1 and t 2 whose scores are (a1 , b1 ) and (a2 , b2 ). The score of team t 1 is better than that of t 2 if either a1 > a2 , or if a1 = a2 and b1 < b2 . The rank of a team is k + 1 where k is the number of teams whose score is better.
You would like to follow the performance of your favorite team. Unfortunately, the organizers of GCPC do not provide a scoreboard. Instead, they send a message immediately whenever a team solves a problem.
This year there are n teams in the contest. The teams are numbered 1, 2, . . . , n, and your favorite team has number 1.
Like today, the score of a team is a pair of integers (a, b) where a is the number of solved problems and b is the total penalty of that team.
When a team solves a problem there is some associated penalty (not necessarily calculated in the same way as in the NCPC – the precise details are not important in this problem). The total penalty of a team is the sum of the penalties for the solved problems of the team.
Consider two teams t 1 and t 2 whose scores are (a1 , b1 ) and (a2 , b2 ). The score of team t 1 is better than that of t 2 if either a1 > a2 , or if a1 = a2 and b1 < b2 . The rank of a team is k + 1 where k is the number of teams whose score is better.
You would like to follow the performance of your favorite team. Unfortunately, the organizers of GCPC do not provide a scoreboard. Instead, they send a message immediately whenever a team solves a problem.
输入
The first line of input contains two integers n and m, where 1 ≤ n ≤ 105 is the number of teams,and 1 ≤ m ≤ 105 is the number of events.
Then follow m lines that describe the events. Each line contains two integers t and p (1 ≤ t ≤ n and 1 ≤ p ≤ 1000), meaning that team t has solved a problem with penalty p. The events are ordered by the time when they happen.
Then follow m lines that describe the events. Each line contains two integers t and p (1 ≤ t ≤ n and 1 ≤ p ≤ 1000), meaning that team t has solved a problem with penalty p. The events are ordered by the time when they happen.
输出
Output m lines. On the i’th line, output the rank of your favorite team after the first i events have happened.
样例输入
3 4
2 7
3 5
1 6
1 9
样例输出
2
3
2
1
#includeusing namespace std; struct node { int t,p; bool operator<(const node &b)const { if(t!=b.t) return t>b.t; return p<b.p; } }a[100005]; multiset s; int main() { int n,m; scanf("%d%d",&n,&m); for(int i=0;i<=n;i++) { a[i].t=0; a[i].p=0; } int x,y; multiset ::iterator it; while(m--) { scanf("%d%d",&x,&y); // if(s.find(a[x])!=s.end()) // { // s.erase(a[x]); // } if(x==1) { a[x].t++; a[x].p+=y; // if(s.size()==0) // printf("1\n"); // else // { // printf("%d\n",s.size()+1); // } } else { if(a[x].t>a[1].t||(a[x].t==a[1].t&&a[x].p1].p)) { // printf("%d\n",s.size()+1); s.erase(s.find(a[x])); // a[x].t++; // a[x].p+=y; // s.insert(a[x]); // continue; // s.insert(a[x]); // continue; } // else if(a[x]==a[1]) // { // printf("%d\n",s.size()+1); // s // a[x].t++; // a[x].p+=y; // } // if(a[x].t==a[1].t&&a[x].p==a[1].p) // { // if(s.find(a[x])==s.end()) // { // a[x].t++; // a[x].p+=y; // s.insert(a[x]); // printf("%d\n",s.size()+1); // } // else // { // s.erase(s.find(a[x])); // a[x].t++; // a[x].p+=y; // s.insert(a[x]); // printf("%d\n",s.size()+1); // } // continue; // } a[x].t++; a[x].p+=y; s.insert(a[x]); // if(a[x].t>a[1].t||(a[x].t==a[1].t&&a[x].p// { // s.insert(a[x]); // printf("%d\n",s.size()+1); // } // else // { // printf("%d\n",s.size()+1); // } // printf("%d\n",s.size()+2); } // for(it=s.begin();it!=s.end();) // { // if((*it).ta[1].p)) // { // s.erase(it++); // } // else // break; // } while(!s.empty() && !(*--s.end() < a[1])) { s.erase(--s.end()); } printf("%d\n",s.size()+1); } // cout << "Hello world!" << endl; return 0; }
问题 I: Judging Moose
时间限制: 1 Sec 内存限制: 128 MB提交: 120 解决: 66
[提交] [状态] [讨论版] [命题人:admin]
题目描述
When determining the age of a bull moose, the number of tines (sharp points), extending from the main antlers, can be used. An older bull moose tends to have more tines than a younger moose. However, just counting the number of tines can be misleading, as a moose can break off the tines, for example when fighting with other moose. Therefore, a point system is used
when describing the antlers of a bull moose.
The point system works like this: If the number of tines on the left side and the right side match, the moose is said to have the even sum of the number of points. So, “an even 6-point moose”, would have three tines on each side.
If the moose has a different number of tines on the left and right side, the moose is said to have twice the highest number of tines, but it is odd. So “an odd 10-point moose” would have 5 tines on one side, and 4 or less tines on the other side.
Can you figure out how many points a moose has, given the number of tines on the left and right side?
when describing the antlers of a bull moose.
The point system works like this: If the number of tines on the left side and the right side match, the moose is said to have the even sum of the number of points. So, “an even 6-point moose”, would have three tines on each side.
If the moose has a different number of tines on the left and right side, the moose is said to have twice the highest number of tines, but it is odd. So “an odd 10-point moose” would have 5 tines on one side, and 4 or less tines on the other side.
Can you figure out how many points a moose has, given the number of tines on the left and right side?
输入
The input contains a single line with two integers L and r, where 0 ≤ L ≤ 20 is the number of tines on the left, and 0 ≤ r ≤ 20 is the number of tines on the right.
输出
Output a single line describing the moose. For even pointed moose, output “Even x” where x is the points of the moose. For odd pointed moose, output “Odd x” where x is the points of the moose. If the moose has no tines, output “Not a moose”
样例输入
2 3
样例输出
Odd 6
#includeusing namespace std; int a,b; int main() { scanf("%d%d",&a,&b); if(a==0&&b==0) { printf("Not a moose\n"); return 0; } if(a==b) { printf("Even %d\n",a+b); } else { int maxn=max(a,b); printf("Odd %d\n",2*maxn); } return 0; }
J: Kayaking Trip
时间限制: 1 Sec 内存限制: 128 MB提交: 106 解决: 42
[提交] [状态] [讨论版] [命题人:admin]
题目描述
You are leading a kayaking trip with a mixed group of participants in the Stockholm archipelago, but as you are about to begin your final stretch back to the mainland you notice a storm on the horizon. You had better paddle as fast as you can to make sure you do not get trapped on one of the islands. Of course, you cannot leave anyone behind, so your speed will be determined by the slowest kayak.
Time to start thinking; How should you distribute the participants among the kayaks to maximize your chance of reaching the mainland safely?
The kayaks are of different types and have different amounts of packing, so some are more easily paddled than others. This is captured by a speed factor c that you have already figured out for each kayak. The final speed v of a kayak, however, is also determined by the strengths s1 and s2 of the two people in the kayak, by the relation v = c(s1 + s2 ). In your group you have some beginners with a kayaking strength of sb , a number of normal participants with strength s n and some quite experienced strong kayakers with strength se .
Time to start thinking; How should you distribute the participants among the kayaks to maximize your chance of reaching the mainland safely?
The kayaks are of different types and have different amounts of packing, so some are more easily paddled than others. This is captured by a speed factor c that you have already figured out for each kayak. The final speed v of a kayak, however, is also determined by the strengths s1 and s2 of the two people in the kayak, by the relation v = c(s1 + s2 ). In your group you have some beginners with a kayaking strength of sb , a number of normal participants with strength s n and some quite experienced strong kayakers with strength se .
输入
The first line of input contains three non-negative integers b, n, and e, denoting the number of beginners, normal participants, and experienced kayakers, respectively. The total number of participants, b + n + e, will be even, at least 2, and no more than 100 000. This is followed by a line with three integers sb , sn , and se , giving the strengths of the corresponding participants (1 ≤ sb < sn < se ≤ 1 000). The third and final line contains m = (b+n+e)/2 integers c1 , . . . , cm(1 ≤ ci ≤ 100 000 for each i), each giving the speed factor of one kayak.
输出
Output a single integer, the maximum speed that the slowest kayak can get by distributing the participants two in each kayak.
样例输入
3 1 0
40 60 90
18 20
样例输出
1600
#includeusing namespace std; struct node { int first,second,sum; }op[10]; int per[5],s[5],num[5]; int n; int c[50050]; bool check(int mid) { for(int i=1;i<=3;i++) { num[i]=per[i]; } for(int i=1;i<=n;i++) { int flag=0; for(int j=1;j<=6;j++) { if(num[op[j].first]==0||num[op[j].second]==0||op[j].sum*c[i]<mid) { continue; } if(op[j].first==op[j].second&&num[op[j].first]<2) { continue; } num[op[j].first]--; num[op[j].second]--; flag=1; break; } if(flag==0) { return 0; } } return 1; } int main() { scanf("%d %d %d",&per[1],&per[2],&per[3]); scanf("%d %d %d",&s[1],&s[2],&s[3]); n=per[1]+per[2]+per[3]; n/=2; for(int i=1;i<=n;i++) { scanf("%d",&c[i]); } sort(c+1,c+1+n); int k=1; for(int i=1;i<=3;i++) { for(int j=i;j<=3;j++) { op[k].first=i; op[k].second=j; op[k++].sum=s[i]+s[j]; } } int r=400000000,l=0,mid,ans; while(r-l>=0) { mid=(r+l)/2; if(check(mid)) { ans=mid; l=mid+1; } else { r=mid-1; } } printf("%d\n",ans); return 0; }