懒得描述题意了。就是每天必须有k人,还得传递钥匙,工作n天,休息m天。。。。
http://codeforces.com/problemset/problem/216/C
解: 模拟 + 贪心。 重点是模拟到n + m天就行了。
做题过程:people[day]开得不够大,day可以到3000天呢。。。因为这样,输入同一个东西,还能输出不同结果。如801 801 1
/*
Pro: 0
Sol:
date:
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <vector>
using namespace std;
int n,m,k;
int ans [1009 * 1009],people[3010],sub;
int main(){
while(~scanf("%d%d%d",&n,&m,&k)){
memset(people,0,sizeof(people)); sub = 0;
memset(ans,0,sizeof(ans));
for(int i = 1; i <= k; i ++)
ans[sub ++] = 1;//在第一天顾k个人
for(int i = 1; i <= n; i ++)
people[i] = k;//1-n天每天都有k个人
for(int day = n + 1; day <= n + m; day ++){
// cout << "Day = " << day ; printf(" %d\n",sub);
if(people[day] == 0){//如果这天为0个人,那么day - 1得雇个人
ans[sub ++] = day - 1;
//经过调试,发觉当n = m = 801天的时候,这里people[]如果只定义为2000的话会越界。
for(int i = day - 1; i <= day - 1 + n - 1; i ++)
people[i] ++;
}
if(people[day] < k){//这里不能是else if
int add = k - people[day];
for(int i = 1; i <= add; i ++)
ans[sub ++] = day;
for(int i = day; i <= day + n - 1; i ++)
people[i] += add;
}
// cout << "Day = " << day ; printf(" %d\n",sub);
// for(int j = 1; j < n + m; j ++)
// cout << people[j] << " "; cout << people[n + m] << endl;
}
if(people[n + m + 1] == 0) { ans[sub ++] = n + m; }
printf("%d\n",sub);
for(int i = 0; i < sub - 1; i ++)
printf("%d ",ans[i]); printf("%d\n",ans[sub - 1]);
}
return 0;
}