POJ 3190 Stall Reservations

Source: Internet
Author: User

http://poj.org/problem?id=3190

The original idea is sorted by array also good heap maintenance is want to let start time > End time of the cattle merge and then finally find out the number of good
But it doesn't get the distribution of every cow.
So the simulation and greedy heap simulation is milking the machine by the end time from small to large arrangement no search added a cow on the end of a cow milking
This can be used to find out which machine each cow is milking and if the cow is finished by the time it is added to the cow, then it will be ready to use or it can only be added to a new machine.
And then stall is entering a cow to make sure a stall is a pure simulation of this process.
A good problem of greed and imitation

1#include <iostream>2#include <stdio.h>3#include <algorithm>4#include <queue>5 6 using namespacestd;7 8 intN;9 intstall[50003];Ten struct Section One { A     intx, y; -     intPos; -     BOOL operator< (section A)Const //Heap by end time in ascending order the     { -         if(y = = a.y)returnX >a.x; -         Else returnY >a.y; -     } +  -}section[50003]; +  A BOOLCMP (sections A, section B)//array sorted by start time in ascending order at { -     if(a.x = = b.x)returnA.y <b.y; -     Else returnA.x <b.x; - } -  -Priority_queue<section>que; in intSolve () - { to     intAns =0; + Section node; -      for(inti =0; I < N;i + +) the     { *         if( !que.empty ()) $         {Panax Notoginsengnode =que.top (); -             if(Que.top (). Y < section[i].x)//If you add this section to the end of the cow-->>> here is wrong not when the end time and the start time are equal to not be replaced the             { +Stall[section[i].pos] =stall[que.top (). Pos]; AQue.pop ();//This cow's going to be out. the             } +             Else -             { $ans++; $Stall[section[i].pos] =ans; -             } -         } the         Else -         {Wuyians++; theStall[section[i].pos] =ans; -         } Wu Que.push (Section[i]); -     } About     returnans; $ } -  - intMain () - { AFreopen ("In.txt","R", stdin); +      while(~SCANF ("%d", &N)) the     { -          while(!que.empty ()) Que.pop (); $          for(inti =0; i < N; i++) the         { thescanf"%d%d", &section[i].x, &section[i].y); theSection[i].pos =i; the             //Stall[section[i].pos] = i;//arrange the initial stall -         } inSort (section, section+n, CMP);//When you customize a comparison function, you can ignore operator overloads inside the struct the         intAns =solve (); theprintf"%d\n", ans); About          for(inti =0; i < N; i++) the         { theprintf"%d\n", Stall[i]); the         } +     } -     return 0; the}

POJ 3190 Stall Reservations

Related Keywords:

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.