The problem of "greedy" closed interval

Source: Internet
Author: User

Problem X: "Greedy" closed interval problem time limit: 1 Sec memory limit: up to MB
Submitted: Resolution: 9
Submitted State [Discussion Version] The title describes the method of rescuing Li Xulin from the "space-time Trap" by Zhang Qiman, who came back through the magic clock and other students at the Academy of Witchcraft and Wizardry. They set up n monitoring points for historical timelines, each monitoring point can monitor a period of time in history, and we can simply be considered as n-closed intervals on the x-axis. However, some monitoring point monitoring time periods are overlapping, which interferes with the accuracy of monitoring. Try to remove as few closed intervals as possible so that the remaining closed intervals do not intersect. Enter the number n (1≤n≤40000) of the closed interval of the first behavior, followed by the 2 endpoints of the closed interval of n behavior. The output output removes as few as possible the number of closed intervals. Sample input
310 2015 1020 15
Sample output
2
idea: because it is closed interval, more than the previous question increase does not intersect can.
Code:
#include <iostream>#include<cstdio>#include<algorithm>using namespacestd;structnode{intbegin; intend;}; Node tt[ the];intCMP (node A,node b) {returna.end<b.end| | a.end==b.end&&a.begin<B.begin;}intMain () {intN; intT; ints=0; intK//records the last recorded program. //while (scanf ("%d", &n)!=eof&&n) {scanf"%d",&N);  for(intI=0; i<n;i++) {scanf ("%d%d",&tt[i].begin,&tt[i].end); if(tt[i].begin>tt[i].end) {T=Tt[i].begin; Tt[i].begin=Tt[i].end; Tt[i].end=T; }} sort (Tt,tt+n,cmp); S+=1; K=0;  for(intI=1; i<n;i++){            if(tt[i].begin>tt[k].end) {s++; K=i; }} printf ("%d\n", N-s); S=0; //}    return 0;}

The problem of "greedy" closed interval

Related Article

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.