Hdoj 1896 Stones

Source: Internet
Author: User

StonesTime limit:5000/3000 MS (java/others) Memory limit:65535/32768 K (java/others) Total Submission (s): 1474 Accepted Submission (s): 921

Problem Descriptionbecause of the wrong status of the bicycle, SEMPR begin to walk east to West every morning and walk BAC K every evening. Walking may cause a little tired, so sempr always play some games this time.
There was many stones on the road, when he meet a stone, he would throw it ahead as far as possible if it was the odd stone He meet, or leave it where it was if it's the the even stone. Now give your some informations about the stones on the road and you is to tell me the distance from the start point to the F Arthest Stone after Sempr walk by. Please pay attention this if or more stones stay at the same position, you'll meet the larger one (the one with the S Mallest Di, as described in the Input) first.

Inputin the first line, there is a Integer T (1<=t<=10), which means the test cases in the input file. Then followed by T test cases.
For each test case, I'll give you a Integer N (0<n<=100,000) in the first line, which means the number of stones O n the road. Then followed by N lines and there is the integers Pi (0<=pi<=100,000) and Di (0<=di<=1,000) in the line, which means the position of the i-th stone and how far sempr can throw it.

Outputjust output one line to one test case, as described in the Description.

Sample Input
221 52 421) 56 6

Sample Output
/* The main idea is that there are a lot of stones on the road, when you encounter odd sequence of stones put him forward still, even the fixed, two stones together, first consider can throw the relatively close stone is relatively large stone, so go down until all the stones in front can not be thrown so far, the furthest stone distance from the beginning how much!! The topic is very convenient with priority queue */#include <stdio.h> #include <queue> #include <iostream>using namespace std;struct line//defines a structure that stores the current position of the stone and the distance that can be thrown out into the priority queue! {int X;int dis;friend bool operator< (line A,line B)//Then take "smallest" at a time! To pay particular attention to the X-like situation of multiple stones, priority should be given to the stone with the smallest Y value {if (a.x ==b.x) return A.dis >b.dis; return a.x >b.x;}}; int main () {int m,n;priority_queue<line > q;scanf ("%d", &n), line Temp;while (n--) {scanf ("%d", &m);    while (m--) {scanf ("%d%d", &temp.x, &temp.dis);     

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Hdoj 1896 Stones

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.