自己想了很复杂,还考虑了追击再追击的问题,结果做到最后还给了个WA。。faint
查了资料,换个角度想问题居然那么简单。。。。
事实上,只要问自己一个问题就能解决这道题,Charley是和哪一位同时到达?
没错,答案是和最早到达的那个人一起到达的(当然,出发时间<0的不算了)。也就是把问题转化为求出每个人到达的时间即可。
#include<stdio.h>
#define N 100
int main()
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif)
{
int arr_time,last;
int num;
int ii,jj,kk;
int speed;
float tmp;
for(;scanf("%d",&num);)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(!num)
return 1;
for(ii=0,last=10000;ii<num;ii++)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
scanf("%d%d",&speed,&kk);
if(kk>=0)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
tmp=3600*4.5/speed+kk;
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//*printf("tmp:%f %d",tmp,(int)tmp);*/
if(tmp-(int)tmp<.001)
arr_time=(int )tmp;
else
arr_time=1+(int )tmp;
last= ( arr_time<last)?arr_time:last;
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//* printf("last%d",last);*/
}
}
printf("%d\n",last);
}
}