HDU 4585 Shaolin (STL)

Source: Internet
Author: User

# Include <cstdio> # include <iostream> # include <cstring> # include <cmath> # include <map> # include <algorithm> # include <cstdlib> using namespace std; int main () {int n; int id, g; while (scanf ("% d", & n) {map <int, int> m; m [1000000000] = 1; for (int I = 1; I <= n; ++ I) {scanf ("% d", & id, & g ); printf ("% d", id); map <int, int>: iterator it; it = m. lower_bound (g); // finds the first location greater than or equal to g in binary mode. if not, returns the end location if (it = m. End () {it --; printf ("% d \ n", it-> second);} else {if (it = m. begin () {printf ("% d \ n", it-> second);} else {int pos = it-> first; int tmp = it-> second; it --; printf ("% d \ n", (pos-g) <(g-it-> first )? Tmp: it-> second) ;}} m [g] = id ;}} return 0 ;} # include <cstdio> # include <iostream> # include <cstring> # include <cmath> # include <map> # include <algorithm> # include <cstdlib> using namespace std; int main () {int n; int id, g; while (scanf ("% d", & n) {map <int, int> m; m [1000000000] = 1; for (int I = 1; I <= n; ++ I) {scanf ("% d", & id, & g ); printf ("% d", id); map <int, int>: iterator it; it = m. lower_bound (g); // Find the first position greater than or equal to g in the second part. if not, return the end position if (it = m. end () {it --; printf ("% d \ n", it-> second);} else {if (it = m. begin () {printf ("% d \ n", it-> second);} else {int pos = it-> first; int tmp = it-> second; it --; printf ("% d \ n", (pos-g) <(g-it-> first )? Tmp: it-> second) ;}} m [g] = id ;}} 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.