ACM HEU OJ 1019 Ferry Loading II || POJ 2336
来源:互联网 发布:手机处理照片软件 编辑:程序博客网 时间:2024/06/02 02:31
题意:摆渡问题,一个船一次最多能运送n辆汽车。现有m辆汽车需要运送,运输一次的时间为t,求出运送完所有的汽车后的最小时间以及最小的运输次数。
贪心思想:如果m%n==0则运输m/n次 反之则运输 m+1次。
代码如下:
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;void Greedy(int n,int t,int m){ int i,j; int l=m%n; int k=m/n; int now_time; int return_time=0; int trans_time=k; if(l){// trans_time+=1; while(l--){ scanf("%d",&now_time); return_time=now_time+2*t; } } for(i=0;i<k;i++){ for(j=0;j<n;j++) scanf("%d",&now_time);// if(now_time<=return_time) return_time+=2*t; else return_time=now_time+2*t; } printf("%d %d\n",return_time-t,trans_time);}int main(){ int c; scanf("%d",&c); while(c--){ int n,t,m; scanf("%d%d%d",&n,&t,&m); Greedy(n,t,m); } return 0;}
0 0
- ACM HEU OJ 1019 Ferry Loading II || POJ 2336
- poj 2336 Ferry Loading II
- POJ 2336 Ferry Loading II [贪心 DP]
- poj 2336 Ferry Loading II 贪心
- POJ 2336 Ferry Loading II 动态规划
- 贪心之 Ferry Loading II (POJ 2336)
- POJ 2336 动态规划(DP) Ferry Loading II
- POJ 2336 Ferry Loading II (贪心或动态规划)
- POJ-2336 Ferry Loading II(简单DP)
- HRBEU/HEUOJ----1019 Ferry Loading II
- Ferry Loading II
- POJ 2336 Ferry Loading II(运车过河的最短时间和次数)
- ZOJ 1918 Ferry Loading II
- 【贪心】poj2336 ferry loading II
- Ferry Loading II 贪心算法
- uva 10440 Ferry Loading II
- uva 10440 Ferry Loading II
- UVa 10440 - Ferry Loading II
- Android消息推送机制
- 汇编中常见的一些错误信息
- 黑马程序员--Java 7K面试题之交通灯管理系统
- 赡假残压泊俦崭残胀仁辉素
- LDAP入门
- ACM HEU OJ 1019 Ferry Loading II || POJ 2336
- GPU方法做倒排压缩和交集计算
- BaseServlet思想(Struts2的思想)
- C++获取网站的ip地址
- 一个简单有趣的题(4个变量找出取走的数)
- 关于Java中的instanceof关键字
- IOS学习笔记-5
- 腾讯社招面试经历
- Activity、Task、应用和进程