STL (pair map set vector priority_queue) POJ 3297

Source: Internet
Author: User

POJ 3297 Algorithm Competition Junior Chowder Bag

Test instructions: Students choose a class, and no student can choose a course. Uppercase characters are the names of classes, and lowercase are names. If there is more than one name at the end of the course, if a person has more than one course, then he will not attend classes, output classes and the number of elective courses in each course.

Ideas:

Map<string,set<int> > Stu: A student name corresponds to which course he chose.

Map<string,ser<int> > Pro: Course name corresponds to a few students who chose him, set the corresponding students

vector<pair<int,string> > ANS: The final result, the course name corresponds to the number of students selected

A[]: Judging whether a student has chosen only one course

1 //#pragma COMMENT (linker, "/stack:167772160")//Manual expansion of the ~~~~HDU with C + + intersection2#include <cstdio>3#include <cstring>4#include <cstdlib>5#include <iostream>6#include <queue>7#include <stack>8#include <cmath>9#include <Set>Ten#include <utility> One#include <algorithm> A#include <vector> -#include <map> - //#include <malloc.h> the using namespacestd; - #defineCLC (A, B) memset (A,b,sizeof (a)) - #defineLL Long Long - Const intINF =0x3f3f3f3f; + Const DoubleEPS = 1e-5; - Const DoublePI = ACOs (-1); + ConstLL MOD = 1e9+7; A //const LL p = 1e9+7; at //Inline int R () { - //int X=0,f=1;char Ch=getchar (); - //While (ch> ' 9 ' | | ch< ' 0 ') {if (ch== '-') F=-1;ch=getchar ();} - //while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} - //return x*f; - // } inmap<string,int>Stu; -map<string,Set<int> >Pro; tovector<pair<int,string> >ans; +  - inta[10010],n,m; the stringStr,book; * voidinit () { $ stu.clear ();Panax Notoginseng pro.clear (); - ans.clear (); theCLC (A,0); +n=m=0; A } the  + BOOLcmpConstpair<int,string> &a,Constpair<int,string> &b) { -    if(A.first==b.first)returna.second<B.second; $    returnA.first>B.first; $ } -  - voidWork () { thestd::map<string,Set<int> >:: iterator it; -STD::Set<int>:: iterator Q;Wuyi     for(It=pro.begin (); It!=pro.end (); it++){ the       intCnt=0; -        for(Q=it->second.begin (); Q!=it->second.end (); q++){ Wu          if(a[*q]==1) cnt++; -       } AboutAns.push_back (Make_pair (cnt,it->First ));  $    } - sort (Ans.begin (), Ans.end (), CMP); -std::vector<pair<int,string> >:: iterator P; -     for(P=ans.begin ();p!=ans.end ();p + +){ Acout<<p->second<<" "<<p->first<<Endl; +    } the } -  $ intMain () { the     //freopen ("In.txt", "R", stdin); the init (); the      while(Getline (cin,str)) { the        if(str[0]=='0') Break; -        Else if(str[0]=='1') { in Work (); the init (); the           Continue; About        }  the        Else{ the           if(str[0]>='A'&&str[0]<='Z'){ thebook=str; +Pro[book].insert (-1); -           } the           Else{Bayistd::map<string,int>::iterator it =stu.find (str); the              if(it==stu.end ()) thestu[str]=m++; -STD::Set<int>::iterator q=Pro[book].find (Stu[str]); -              if(q==Pro[book].end ()) { thea[stu[str]]++; the Pro[book].insert (Stu[str]); the              } the           } -        } the     } the     return 0; the}

STL (pair map set vector priority_queue) POJ 3297

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.