Hdoj 4004 the frog's games binary

Source: Internet
Author: User

This question was not answered in last year's online competition...
It seems that the difficulty is similar to that of the for loop.
After you have obtained the accesskey for the five binary questions, use hash to make another step.
Tutoring ....

Idea: Search for the shortest capacity of the river crossing in binary mode. Use the capability value to cross the river...
Correct judgmentAlgorithmTime complexity can save a lotCodeTime... taught ....
The original question is used for two points, and the comparison is based on the number of jumps. Later I found that it does not need to be twice ..

# Include <iostream> # include <algorithm> # define INF 0x7fffffffusing namespace STD; int L, n, m; int stone [555555]; bool canjump (int AB) {int cur = 0; For (INT I = 1; I <= m; I ++) {Int J; For (j = cur; stone [J + 1]-stone [cur] <= AB; j ++); cur = J; If (cur = N) return true;} return false ;} int main () {While (scanf ("% d", & L, & N, & M )! = EOF) {memset (stone, 0x7f, sizeof (Stone); stone [0] = 0; For (INT I = 1; I <= N; I ++) scanf ("% d", & stone [I]); stone [++ N] = L; sort (stone + 1, stone + n + 1 ); int Maxx =-1; for (INT I = 1; I <= N; I ++) Maxx = max (Maxx, stone [I]-stone [I-1]); int L = Maxx, r = L, mid; while (mid = (L + r)/2, l <r) {If (canjump (MID) r = mid; else l = Mid + 1;} printf ("% d \ n", mid);} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.