ZOJ——3464 Rugby Football
来源:互联网 发布:凯聪智云软件下载 编辑:程序博客网 时间:2024/04/28 03:49
题意:N个人进行带球训练,训练场长度为L,每个人最多带球时间为T,且传球只能传给与自己平行或在自己后面的队友,每个人的速度V不一样。在球场一侧起跑线从第一个人带球跑动开始计时,问将球带到球场另一侧所需最短时间为多少。
解题思路:若使时间最短,依次将速度较大球员安排在路程的后面,最大的安排在最后面且带球时间必须为T,可以逆向方式考虑,速度最大的球员从终点开始向起点跑,且带球时间为T,接着速度较大的依次带球,直到到达起点。
代码:
#include <iostream>#include <algorithm>#include <cstdio>using namespace std;const int maxn = 10010;int speed[maxn];int main(){ double time; int cas,N,T,L,flag; scanf("%d",&cas); while(cas--) { scanf("%d%d%d",&N,&T,&L); for(int i = 0; i < N; i++) scanf("%d",&speed[i]); time = 0, flag = 0; sort(speed,speed+N); for(int j = N-1; j >= 0; j--) { if(L <= speed[j]*T) { time += L*1.0/speed[j]; flag = 1; break; } if(L > speed[j]*T) { time += T; L = L - speed[j]*T;} } if(flag) printf("%.2lf\n",time); else printf("-1\n"); } return 0;}
0 0
- ZOJ——3464 Rugby Football
- ZOJ 3464 Rugby Football 水题
- ZOJ-#3464 Rugby Football(贪心)
- BNU Rugby Football
- zoj3464 Rugby Football(贪心)
- poj3071——Football
- ZOJ 3355 Football Gambling I
- zoj 3355 Football Gambling I
- 【贪心】UVALive 6530——Football
- Hdu5873——Football Games(模拟)
- codeforces100078H——History of Football
- ZOJ 2524- Football Match (模拟+map)
- Football
- Football
- Football
- Football
- Football
- Football
- 并发模式(三)——生产者-消费模式
- hdu 5057 Argestes and Sequence
- 静态类型检查与继承
- HDU 1098解题报告
- 在VM中安装Android4.4连接小米手机 之 安装小米手环APP
- ZOJ——3464 Rugby Football
- 字符串和数字转换
- H265 SAO 技术
- 程序员求职之道(《程序员面试笔试宝典》)
- 【Unity3D】 KeyCode 键码
- poj - 1170 - Shopping Offers(状态压缩dp)
- 在VM中安装Android4.4连接小米手环 之 设置蓝牙
- poj1654--Area(几何求面积)
- .net 获取odbc驱动列表