hdu4393(模拟+queue)
来源:互联网 发布:天价域名排行 编辑:程序博客网 时间:2024/05/21 20:28
Throw nails
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1007 Accepted Submission(s): 323
Problem Description
The annual school bicycle contest started. ZL is a student in this school. He is so boring because he can't ride a bike!! So he decided to interfere with the contest. He has got the players' information by previous contest video. A player can run F meters the first second, and then can run S meters every second.
Each player has a single straight runway. And ZL will throw a nail every second end to the farthest player's runway. After the "BOOM", this player will be eliminated. If more then one players are NO.1, he always choose the player who has the smallest ID.
Each player has a single straight runway. And ZL will throw a nail every second end to the farthest player's runway. After the "BOOM", this player will be eliminated. If more then one players are NO.1, he always choose the player who has the smallest ID.
Input
In the first line there is an integer T (T <= 20), indicates the number of test cases.
In each case, the first line contains one integer n (1 <= n <= 50000), which is the number of the players.
Then n lines follow, each contains two integers Fi(0 <= Fi <= 500), Si (0 < Si <= 100) of the ith player. Fi is the way can be run in first second and Si is the speed after one second .i is the player's ID start from 1.
Huge input, scanf is recommended.
Huge output, printf is recommended.
In each case, the first line contains one integer n (1 <= n <= 50000), which is the number of the players.
Then n lines follow, each contains two integers Fi(0 <= Fi <= 500), Si (0 < Si <= 100) of the ith player. Fi is the way can be run in first second and Si is the speed after one second .i is the player's ID start from 1.
Hint
Huge input, scanf is recommended.
Huge output, printf is recommended.
Output
For each case, the output in the first line is "Case #c:".
c is the case number start from 1.
The second line output n number, separated by a space. The ith number is the player's ID who will be eliminated in ith second end.
c is the case number start from 1.
The second line output n number, separated by a space. The ith number is the player's ID who will be eliminated in ith second end.
Sample Input
23100 1100 23 10051 12 23 34 13 4
Sample Output
Case #1:1 3 2Case #2:4 5 3 2 1本题若果只是模拟而不用STL优化的话,我想是很容易超时的,我用的模拟+STL,时间复杂度为O(N*S*logM)。总共选n次,0-n-1,正好可以当做秒数,F+i*S为当前每个的路程,其中可以以S把数据分成100组,每组的后面速度相同,只取决于F,从而对于每组建立优先级队列,对头的总是F最大,且在F相同的情况下下表序号最小。#include<stdio.h>#include<iostream>#include<queue>#include<algorithm>using namespace std;struct Node{ int F,S; int index;};struct cmp////////////////////////注意优先级队列的排序方式{ bool operator()(Node a,Node b) { if(a.F!=b.F) return a.F<b.F;///F从大到小排序 return a.index>b.index;//index从小到大排序 }};priority_queue<Node,vector<Node>,cmp>qq[110];///////////////////int main(){ int cas,i,n,j,tag=1; cin>>cas; while(cas--) { scanf("%d",&n); Node tmp; for(i=0;i<n;i++) { scanf("%d%d",&tmp.F,&tmp.S); tmp.index=i+1; qq[tmp.S].push(tmp); }printf("Case #%d:\n",tag++); for(i=0;i<n;i++) { int Max=-1,ind; for(j=1;j<=100;j++) { if(!qq[j].empty()) { tmp=qq[j].top(); // cout<<"j="<<j<<" tmp.F="<<tmp.F<<endl; if(tmp.F+j*i>Max) Max=tmp.F+j*i,ind=j; else if(tmp.F+j*i==Max&&tmp.index<(qq[ind].top()).index) ind=j; } }printf("%d",qq[ind].top().index); qq[ind].pop(); if(i!=n-1) printf(" "); else printf("\n"); } } return 0;}
- hdu4393(模拟+queue)
- hdu4393 Throw nails【优先队列&&贪心&&模拟】
- stack 模拟 queue
- queue 模拟 stack
- 模拟实现queue
- HDU5249(set+queue模拟)
- queue模拟小案例
- 12100-Printer Queue【STL模拟】
- Python 模拟简单的queue
- Codeforces 490B - Queue (模拟)
- Team Queue (uva540 队列模拟)
- 队列Queue模拟排队问题
- 模拟实现 stack和queue
- HOJ 1456 Team Queue(用queue进行模拟)
- UVa 540 Team Queue (STL list&queue模拟插队)
- ZOJ2724 Windows Message Queue 裸queue的模拟
- 模拟window Message Queue 消息队列 算法
- Uva 133 - The Dole Queue//模拟,链表
- 漫谈android开发之菜单(一)
- flex提示安全沙箱
- 哈佛为什么群星闪耀?
- 创业家能从 1930 年代经济大恐慌中学到的五个经验
- VLC测试RTSP请求,附RTSP交互流程
- hdu4393(模拟+queue)
- visual c++ 动态链接库调用总结
- UVA 11375 - Matches
- UNIX 高手的 10 个习惯
- RTSP点播消息流程实例(客户端:VLC, RTSP服务
- 字母小游戏
- 6174问题
- uva 11520 Fill the Square(DFS)
- 算法题求解:从1~N中求某个字符出现次数