acm 1014 满载问题
来源:互联网 发布:淘宝好评80字 编辑:程序博客网 时间:2024/06/07 02:21
1.1014
2.
There is a ferry across the river that can take n cars across the river in t minutes and return in t minutes. m cars arrive at the ferry terminal by a given schedule. What is the earliest time that all the cars can be transported across the river? What is the minimum number of trips that the operator must make to deliver all cars by that time?
22 10 1001020304050607080902 10 3103040
100 550 2
3.贪心思想
4.
在没有达到最后N个人之前,ferry都是满载才出发.(参考飘羽逸狂)
如果当前达到了倒数的第N个人,那么不论此时ferry中有多少人,都要出发,ferry回来之后再把剩下的N个人都载过去.
对于当前到达的人,假设是第k个人,考虑是否将其装入ferry对于第k+n个人的影响
如果不装入,那么ferry回来的时间是至少是tt[k-1]+2*d,这么一来装入第k+n个人的时间至少是tt[k-1]+2*d+2*d
如果装入,那么回来的时间至少是tt[k]+2*d
并且tt[k-1]+2*d>tt[k]
因为如果tt[k-1]+2*d<=tt[k]
总可以将第k-1个人提前运走
因此结论就是
在没有达到最后N个人之前,ferry都是满载才出发.
5
#include<iostream>
#include<cstring>
#include<stdio.h>
#include<string>
#include<stack>
#include<map>
#include<vector>
#include<cmath>
#include<set>
#include<cctype>
#include<queue>
using namespace std;
int n,t,m;
int time[10000];
void clear() {
memset(time,0,sizeof(time));
}
int main() {
int Case;
scanf("%d",&Case);
while(Case--) {
scanf("%d %d %d",&n,&t,&m);
clear();
int r = m%n;
int k = m/n;
int ans1 = 0,ans2;
if(r)
ans2 = k + 1;
else
ans2 = k;
for(int i=1;i<=m;i++)
scanf("%d",&time[i]);
if(r)
ans1 = time[r] + t * 2;
int j = 1;
while(j <= k) {
if(ans1 >= time[j * n + r]) {
ans1 += t * 2;
if(j == k)
ans1 -= t;
}
else {
ans1 = time[j * n + r] + t * 2;
if(j == k)
ans1 -= t;
}
j++;
}
printf("%d %d\n",ans1,ans2);
}
return 0;
}.
- acm 1014 满载问题
- python 让cpu满载
- ACM 1014 Dividing 背包问题
- 首做acm问题
- 浙大acm问题1003
- acm 蟠桃计问题
- 一个ACM问题
- 导弹拦截问题ACM
- ACM 任务分配问题
- acm--合并国家问题
- ACM 3984 迷宫问题
- ACM -- 凸包问题
- ACM -- 八皇后问题
- ACM 问题分类
- ACM小问题总结
- ACM之舞伴问题
- 求和的问题ACM
- A+B问题acm
- leetcode 275. H-Index II
- JS 中 cookies 的使用
- 分享一个JQuery写的点击上下滚动的小例子
- hdu 1245 Saving James Bond 最短路spfa+简单计算几何
- 作文网高并发环境下如何使用MySQL
- acm 1014 满载问题
- mysql 中使用group by分组时如何计总数
- android studio开发安卓应用设置版本号
- java集合,ArrayList,LinkedList知识点总结
- view 中函数的调用顺序,以xib自定义view为例
- 关于角色攻击范围判定和攻击判定
- Qt实现Ribbon效果
- 循环队列
- oc内存管理