ZOJ-#3464 Rugby Football(贪心)
2014-09-15 15:16
337 查看
题目大意:有n个人,有不同的速度,从起跑线出发,可以不同时,但每个人拿球的时间不能超过t,球只能水平以及向后传递。问最短跑到达阵区的时间是多少,不能完成输出-1.
解题思路:由题意可知,应该尽量让速度快的跑完整个时间,而不用考虑速度快的何时起跑以及怎样衔接,因为速度快的始终能够达到接球时所需要的状态。直接贪心就可以了,详见code。
题目来源:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3464
code:
解题思路:由题意可知,应该尽量让速度快的跑完整个时间,而不用考虑速度快的何时起跑以及怎样衔接,因为速度快的始终能够达到接球时所需要的状态。直接贪心就可以了,详见code。
题目来源:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3464
code:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int MAXN = 1e4; int n,rp; double t,l,s; double ans; int v[MAXN]; int main(){ //freopen("input.txt","r",stdin); scanf("%d",&rp); while(rp--){ memset(v,0,sizeof(v)); scanf("%d%lf%lf",&n,&t,&l); s=0;ans=0; for(int i=0;i<n;i++){ scanf("%d",v+i); s+=v[i]; } if(s*t<l){printf("-1\n");continue;} //所有人都不能完成,则输出-1 sort(v,v+n); for(int i=n-1;i>=0;i--){ if(v[i]*t>=l){ans+=l/v[i];break;} //最快的那个人就可以跑完 if(v[i]*t<=l){ //让速度最快的最后跑完所有时间 ans+=t; l-=v[i]*t; if(0==l) break; } else if(l*1.0/v[i]<t){ //不足的由前面速度次慢的补上 ans+=l*1.0/v[i]; break; } } printf("%.2lf\n",ans); } return 0; }
相关文章推荐
- ZOJ 3464 Rugby Football 水题
- ZOJ——3464 Rugby Football
- zoj 3211 dream city 贪心 dp和记忆化搜索
- 【DBSDFZOJ 4846】攻略(贪心)
- ZOJ 3715 Kindergarten Election(枚举+贪心)
- [贪心+dfs] ZOJ 3761 Easy billiards
- ZOJ 3715 Kindergarten Election(枚举+贪心)
- ZOJ 3790 Consecutive Blocks 贪心
- ZOJ-2364 Data Transmission 分层图阻塞流 Dinic+贪心预流
- ZOJ 2315 New Year Bonus Grant(贪心)
- 贪心加暴力(ZOJ 3715,Kindergarten Election)
- ZOJ 3963 Heap Partition( 并查集 + 贪心 +二分 )
- ZOJ - 3956 Course Selection System 贪心-背包思想
- ZOJ 3689 Digging(贪心+dp)
- ZOJ1076-Gene Assembly(贪心)
- ZOJ-#3519 Who is the Smartest Man(贪心)
- ZOJ-3905-Cake【贪心】【dp】
- ZOJ 1985 Largest Rectangle in a Histogram 迭代... 贪心
- ZOJ 3474 Taekwondo【贪心】
- ZOJ 3569 Dr. Zomboss's Revenge(贪心)