# pku 1771Elevator Stopping Plan

563人阅读 评论(0)

http://acm.pku.edu.cn/JudgeOnline/problem?id=1064,这个也是的，二分枚举+验证。

/*change from 1774*/
#include <iostream>
#define N 30001
using namespace std;

bool stop[N];
int n;
int stk[N];

bool satisfy(int t)
{
int I,J=0,nStop=0;

I=(t/20+1+1); // below(not including) walk
while (I<n)
{
while (I<n && stop[I] == false) ++I;
if (I>=n) return true;
if ((I-1)*4 + nStop*10>t)
return false;
J = (t + 4 + 20*I - 10*nStop)/24; // elevator stops here
I = (t + 16*J + 4 -10*nStop)/20 +1; // below (not inclu.) ok
++ nStop;

}
return true;
}
void print(int t)
{
int I,J=0,nStop=0;

I=(t/20+1+1); // below(not including) walk
while (I<n)
{
while (I<n && stop[I] == false) ++I;

if (I>=n) break;

J = (t + 4 + 20*I - 10*nStop)/24; // elevator stops here
I = (t + 16*J + 4 -10*nStop)/20 +1; // below (not inclu.) ok
stk[nStop] = J;
++ nStop;
}
printf("%d",nStop);
for (int I=0; I<nStop; ++I)
{
printf(" %d",stk[I]);
}
printf("/n");
}

int main()
{
int I,J;
int high;

while (scanf("%d",&n)!=EOF)
{
if (n==0) break;

memset(stop,0,sizeof(stop));

high=0;

for (I=0; I<n; ++I)
{
scanf("%d",&J);
high=max(high,J);
stop[J] = true;
}

int maxt, mint, midt;

maxt=12*high+24;
mint=0;

n = high+1;

while (mint<=maxt)
{
midt=(mint+maxt)/2;

if (satisfy(midt))
{
maxt=midt-1;
}
else
{
mint=midt+1;
}
}

printf("%d/n",mint);
print(mint);
}
}


个人资料
等级：
访问量： 4万+
积分： 845
排名： 5万+
文章分类
最新评论