The Frog’s Games
Problem Description
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
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
Sample Input
6 1 2
2
25 3 3
11
2
18
Sample Output
4
11
Analysis:
It is the opposite bank where a frog wants to jump, and then there are M stones in the middle of the river, and then it can jump up to k times. Ask the frog how long it needs to jump the shortest Only when it is far away can it be guaranteed not to fall. According to my idea, if all m stones are jumped, they need to jump M+1 times. Then if k >= M+1 times, it is enough to find the one with the largest distance between the two stones. But if k View Code div> 1 #include
2
3 using namespace std;
4
5 const int N = 500010;
6
7 int ans[N];
8
9 int ll, nn, mm;
10
11
12 bool judge (int dis) {
13 int tx = 0, i, ty = 0;
14 for (int i = 1; i <= mm; i++) {
15 while (ty <= nn + 1 && ans[ty]-ans[tx] <= dis) ty++;
16
17 ty --;
18 tx = ty;
19 }
20 return ty == nn + 1;
21 }
22
23 int main () {
24
25 while (~scanf("%d %d %d", &ll , &nn, &mm)) {
26
27 for (int i = 1; i <= nn; i++) {
28 scanf("%d", &ans[i]);
29 }
30 ans[0] = 0; ans[nn+1] = ll;
31 sort(ans, ans + nn +1 );
32 int L = 0, R = ll;
33 while (L <= R) {
34 int mid = (L + R)> > 1;
35 if (judge(mid)) {
36 R = mid-1;
37} else L = mid + 1;
38 }
39 printf("%d
", L);
40 }
41 return 0;
42 }
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.
For each case, output a integer standing for the frog’s ability at least they should have.
6 1 2
2
25 3 3
11
2
18
4
11
Analysis:
It is the opposite bank where a frog wants to jump, and then there are M stones in the middle of the river, and then it can jump up to k times. Ask the frog how long it needs to jump the shortest Only when it is far away can it be guaranteed not to fall. According to my idea, if all m stones are jumped, they need to jump M+1 times. Then if k >= M+1 times, it is enough to find the one with the largest distance between the two stones. But if k View Code div> View Code p> WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist] 1 #include
2
3 using namespace std;
4
5 const int N = 500010;
6
7 int ans[N];
8
9 int ll, nn, mm;
10
11
12 bool judge (int dis) {
13 int tx = 0, i, ty = 0;
14 for (int i = 1; i <= mm; i++) {
15 while (ty <= nn + 1 && ans[ty]-ans[tx] <= dis) ty++;
16
17 ty --;
18 tx = ty;
19 }
20 return ty == nn + 1;
21 }
22
23 int main () {
24
25 while (~scanf("%d %d %d", &ll , &nn, &mm)) {
26
27 for (int i = 1; i <= nn; i++) {
28 scanf("%d", &ans[i]);
29 }
30 ans[0] = 0; ans[nn+1] = ll;
31 sort(ans, ans + nn +1 );
32 int L = 0, R = ll;
33 while (L <= R) {
34 int mid = (L + R)> > 1;
35 if (judge(mid)) {
36 R = mid-1;
37} else L = mid + 1;
38 }
39 printf("%d
", L);
40 }
41 return 0;
42 } 1 #include
2
3 using namespace std;
4
5 const int N = 500010;
6
7 int ans[N];
8
9 int ll, nn, mm;
10
11
12 bool judge (int dis) {
13 int tx = 0, i, ty = 0;
14 for (int i = 1; i <= mm; i++) {
15 while (ty <= nn + 1 && ans[ty]-ans[tx] <= dis) ty++;
16
17 ty --;
18 tx = ty;
19 }
20 return ty == nn + 1;
21 }
22
23 int main () {
24
25 while (~scanf("%d %d %d", &ll , &nn, &mm)) {
26
27 for (int i = 1; i <= nn; i++) {
28 scanf("%d", &ans[i]);
29 }
30 ans[0] = 0; ans[nn+1] = ll;
31 sort(ans, ans + nn +1 );
32 int L = 0, R = ll;
33 while (L <= R) {
34 int mid = (L + R)> > 1;
35 if (judge(mid)) {
36 R = mid-1;
37} else L = mid + 1;
38 }
39 printf("%d
", L);
40 }
41 return 0;
42 } 1 #include
2
3 using namespace std;
4
5 const int N = 500010;
6
7 int ans[N];
8
9 int ll, nn, mm;
10
11
12 bool judge (int dis) {
13 int tx = 0, i, ty = 0;
14 for (int i = 1; i <= mm; i++) {
15 while (ty <= nn + 1 && ans[ty]-ans[tx] <= dis) ty++;
16
17 ty --;
18 tx = ty;
19 }
20 return ty == nn + 1;
21 }
22
23 int main () {
24
25 while (~scanf("%d %d %d", &ll , &nn, &mm)) {
26
27 for (int i = 1; i <= nn; i++) {
28 scanf("%d", &ans[i]);
29 }
30 ans[0] = 0; ans[nn+1] = ll;
31 sort(ans, ans + nn +1 );
32 int L = 0, R = ll;
33 while (L <= R) {
34 int mid = (L + R)> > 1;
35 if (judge(mid)) {
36 R = mid-1;
37} else L = mid + 1;
38 }
39 printf("%d
", L);
40 }
41 return 0;
42 }SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 1724 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC