The 36th ACM/ICPC Asia Regional Dalian Site 1003 The Frog's Games
2016-09-15 18:27
399 查看
The Frog's Games
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65768/65768K (Java/Other)
Total Submission(s) : 7 Accepted Submission(s) : 3
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
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).
Input
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.
Output
For each case, output a integer standing for the frog's ability at least they should have.
Sample Input
6 1 2 2 25 3 3 11 2 18
Sample Output
4 11
Source
The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest总结:
不难发现,如果我们正向来看这个问题的话,我们要解决的问题就是从点集中选择m-1个点使得它们与相邻的两个点直接间最大距离最小,看到使最大距离最小的问题,从正面一般不好解决,从反面很容易想到二分法,所以我们直接二分答案即可// // main.cpp // The Frog's Games // // Created by 张嘉韬 on 16/9/15. // Copyright © 2016年 张嘉韬. All rights reserved. // #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; int l,n,m; int map[500000+10]; void init() { map[0]=0; for(int i=1;i<=n;i++) { scanf("%d",&map[i]); } map[n+1]=l; sort(map+0,map+n+1); } int find(int now,int p) { int temp=now; while(map[temp]<=p) { temp++; } return temp-1; } int judge(int d) { int flag=0; int father=0; int now=0; int counter=0; while(1) { father=now; int p=map[now]+d; if(p<l) now=find(now,p); else now=n+1; counter++; if(now==n+1) {flag=1; break;} else if(father==now||counter>=m) break; } return flag; } int search(int s,int e) { if(s==e&&judge(s)) return s; int m=(s+e)/2; if(judge(m)) return search(s,m); else return search(m+1,e); } int main(int argc, const char * argv[]) { //freopen("/Users/zhangjiatao/Documents/ACM/input.txt","r",stdin); while(scanf("%d%d%d",&l,&n,&m)==3) { init(); // find() int ans=search(0,l); printf("%d\n",ans); } return 0; }
相关文章推荐
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest &&The Frog's Games
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest &&Dave
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest &&To Miss Our Children Time
- 4007 Dave(The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest)
- The 36th ACM/ICPC Asia Regional Dalian Site 1004 The kth great number
- 2011 大连网络赛 The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest 解题报告
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest hdu4001
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest Find the maximum
- The 36th ACM/ICPC Asia Regional Dalian Site 1006 Dave
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest hdu4002
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest(套题HDU4001-4010)
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest hdu4007
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest &&The kth great number
- The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest
- The 36th ACM/ICPC Asia Regional Shanghai Site —— Warmup hdu 4016 Magic Bitwise And Operation
- The 36th ACM/ICPC Asia Regional Beijing Site Online Contest - B Eliminate Witches!
- HDU 4069 Squiggly Sudoku(DLX)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)
- 4046 Panda(The 36th ACM/ICPC Asia Regional Beijing Site —— Online Contest)
- hdu 4027 Can you answer these queries? The 36th ACM/ICPC Asia Regional Shanghai Site
- 4045 Machine scheduling(The 36th ACM/ICPC Asia Regional Beijing Site —— Online Contest)