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?
2 2 10 10 0 10 20 30 40 50 60 70 80 90 2 10 3 10 30 40
100 5 50 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;
}.