Row seats (greedy)

Source: Internet
Author: User

Bath Valley 1056

Test instructions: The second problem of Noip2008 popularization group

Analysis: Because the minimum number of discussion groups is required and is output in ascending order. First, we count the number of people in the row (column) to stop the discussion and sort the results in descending order, and then we'll sort the results in ascending order of numbers.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <string>5#include <vector>6#include <algorithm>7#include <Set>8#include <map>9#include <bitset>Ten#include <cmath> One#include <queue> A#include <stack> - using namespacestd; - Const intmaxn=2020; thetypedefstruct Point - { -     intNum,id; - }point; + Point A[MAXN],B[MAXN]; - //int A[MAXN],B[MAXN]; + intm,n,k,l,d; A BOOLCMP1 (ConstPoint A,ConstPoint B) at { -     returnA.num>B.num; - } - BOOLCMP2 (ConstPoint A,ConstPoint B) - { -     returna.id<b.id; in } - intMain () to { +      while(cin>>m>>n>>k>>l>>d) -     { the          for(intI=0; i<maxn;i++) *         { $A[i].id=b[i].id=i;Panax Notoginsenga[i].num=b[i].num=0; -         } the          for(intI=0; i<d;i++) +         { A             intx,y,p,q,h; thescanf"%d%d%d%d",&x,&y,&p,&q); +             if(x==p) { -H=min (y,q); $b[h].num++; $             } -             if(y==q) -             { theH=min (x,p); -a[h].num++;Wuyi             } the         } -Sort (a,a+maxn,cmp1); WuSort (b,b+maxn,cmp1); -Sort (a,a+k,cmp2); AboutSort (b,b+l,cmp2); $          for(intI=0; i<k;i++){ -cout<<a[i].id<<" "; -         } -cout<<Endl; A          for(intI=0; i<l;i++) +         { thecout<<b[i].id<<" "; -         } $cout<<Endl; the     } the     return 0; the}
View Code

Row seats (greedy)

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.