2015
04-14

# The Frog’s Games

The annual Games in frogs’ kingdom started again. The most famous game is the Ironfrog Triathlon. One test in the Ironfrog Triathlon is jumping. This project requires the frog athletes to jump over the river. The width of the river is L (1<= L <= 1000000000). There are n (0<= n <= 500000) stones lined up in a straight line from one side to the other side of the river. The frogs can only jump through the river, but they can land on the stones. If they fall into the river, they
are out. The frogs was asked to jump at most m (1<= m <= n+1) times. Now the frogs want to know if they want to jump across the river, at least what ability should they have. (That is the frog’s longest jump distance).

The input contains several cases. The first line of each case contains three positive integer L, n, and m.
Then n lines follow. Each stands for the distance from the starting banks to the nth stone, two stone appear in one place is impossible.

The input contains several cases. The first line of each case contains three positive integer L, n, and m.
Then n lines follow. Each stands for the distance from the starting banks to the nth stone, two stone appear in one place is impossible.

6 1 2
2
25 3 3
11
2
18

4
11

/*

二分，水。。题。竟然ac了、着实捏了一把冷汗、1Y。。。
读完题后直接就想到二分了、不过看了数据范围后、感脚数据如果够强大

2013-07-03
*/

#include"iostream"
#include"cstdio"
#include"cstring"
#include"algorithm"
using namespace std;
const int N=500005;

int dir[N],dis[N];
int main()
{
int n,m,L;
int i;
int low,mid,up;
int temp,max,cnt;
while(scanf("%d%d%d",&L,&n,&m)!=-1)
{
dis[0]=0;
for(i=1;i<=n;i++)   scanf("%d",&dis[i]);
dis[n+1]=L;
sort(dis,dis+n+2);
max=0;
for(i=0;i<=n;i++)
{
dir[i]=dis[i+1]-dis[i];
if(max<dir[i])  max=dir[i];
}

if(m>n)    {printf("%d\n",max);continue;}
low=max;up=L;
while(low<=up)
{
mid=(low+up)>>1;
i=cnt=0;
while(i<=n && cnt<m)
{
cnt++;
temp=mid;
while(i<=n && dir[i]<=temp)
{
temp-=dir[i];
i++;
}
}
if(cnt<=m && i>n)   up=mid-1;
else    low=mid+1;
}
cout<<low<<endl;
}
return 0;
}


1. #include <stdio.h>
int main()
{
int n,p,t[100]={1};
for(int i=1;i<100;i++)
t =i;
while(scanf("%d",&n)&&n!=0){
if(n==1)
printf("Printing order for 1 pages:nSheet 1, front: Blank, 1n");
else {
if(n%4) p=n/4+1;
else p=n/4;
int q=4*p;
printf("Printing order for %d pages:n",n);
for(int i=0;i<p;i++){
printf("Sheet %d, front: ",i+1);
if(q>n) {printf("Blank, %dn",t[2*i+1]);}
else {printf("%d, %dn",q,t[2*i+1]);}
q–;//打印表前
printf("Sheet %d, back : ",i+1);
if(q>n) {printf("%d, Blankn",t[2*i+2]);}
else {printf("%d, %dn",t[2*i+2],q);}
q–;//打印表后
}
}
}
return 0;
}