Advertisement
ipilot

Pizza

Oct 12th, 2012
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.50 KB | None | 0 0
  1. #pragma warning(disable: 4996)
  2. #pragma comment(linker,"/STACK:64000000")
  3. #include <iostream>
  4. #include <sstream>
  5. #include <stdio.h>
  6. #include <memory.h>
  7. #include <algorithm>
  8. #include <set>
  9. #include <map>
  10. #include <string>
  11. #include <cstring>
  12. #include <vector>
  13. #include <cmath>
  14. #include <queue>
  15. #include <deque>
  16. #include <stack>
  17. #include <cassert>
  18. #include <time.h>
  19. #include <bitset>
  20.  
  21. using namespace std;
  22.  
  23. #define mp make_pair
  24. #define pb push_back
  25. #define _(a,b) memset( (a), b, sizeof( a ) )
  26. #define all(a) a.begin(), a.end()
  27. #define sz(a) (int)a.size()
  28.  
  29. typedef unsigned long long ull;
  30. typedef long long lint;
  31. typedef pair < int , int > pii;
  32. typedef long double ld;
  33.  
  34. const int INF = 1000 * 1000 * 1000;
  35. const lint LINF = 1000000000000000000LL;
  36. const double eps = 1e-9;
  37.  
  38. void prepare(string s)
  39. {
  40. #ifdef _DEBUG
  41.     freopen("input.txt", "r", stdin);
  42. #else
  43.     if (sz(s) != 0)
  44.     {
  45.         freopen((s + ".in").c_str(),"r",stdin);
  46.         freopen((s + ".out").c_str(),"w",stdout);
  47.     }
  48. #endif
  49. }
  50.  
  51. map<pair<string, string>, int> pz;
  52. map<pair<string, string>, int>::iterator it, itd;
  53. map<string, int> fling, mling;
  54. map<string, int>::iterator its;
  55. string flpi[25], mlpi[25], pname;
  56. int flpic, mlpic;
  57. pair <string, string> st;
  58.  
  59. int main()
  60. { int i, j, k, n, u, v;
  61.     prepare("");
  62.     cin >> n;
  63.     for (i=0; i<n; i++)
  64.     {
  65.         cin >> k;
  66.         for (j=0; j<k; j++)
  67.         {
  68.             cin >> pname;
  69.             cin >> flpic;
  70.             for (u=0; u<flpic; u++) cin >> flpi[u];
  71.             cin >> mlpic;
  72.             for (u=0; u<mlpic; u++) cin >> mlpi[u];
  73.             for (u=0; u<flpic; u++)
  74.             {
  75.                 its=fling.find(flpi[u]);
  76.                 if (its != fling.end()) fling[flpi[u]]++; else fling[flpi[u]]=1;
  77.                 for (v=0; v<mlpic; v++)
  78.                 {
  79.                     its=mling.find(mlpi[v]);
  80.                     if (u == 0)
  81.                         if (its != mling.end()) mling[mlpi[v]]++; else mling[mlpi[v]]=1;
  82.                     st=mp(flpi[u],mlpi[v]);
  83.                     it=pz.find(st);
  84.                     if (it != pz.end()) pz[st]++;
  85.                     else
  86.                     {
  87.                         its=fling.find(flpi[u]);
  88.                         if (its->second == 1) pz[st]=1;
  89.                     }
  90.                 }
  91.             }
  92.         }
  93.         for (it=pz.begin(); it != pz.end();)
  94.         {
  95.             if ((it->second < fling[it->first.first]) || (it->second != mling[it->first.second]))
  96.             {
  97.                 itd=it;
  98.                 if (it == pz.begin())
  99.                 {
  100.                     pz.erase(itd);
  101.                     it=pz.begin();
  102.                 }
  103.                 else
  104.                 {
  105.                     --it;
  106.                     pz.erase(itd);
  107.                 }
  108.             }
  109.             else ++it;
  110.         }
  111.         for (it=pz.begin(); it != pz.end(); ++it)
  112.             cout << "(" << it->first.first << ", " << it->first.second << ")\n";
  113.         pz.clear(); fling.clear(); mling.clear();
  114.         if (i < n-1) cout << endl;
  115.     }
  116.     return 0;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement