the_art_of_war

GCJ 1C 2nd problem

May 5th, 2018
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. //#include <cassert>
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. typedef pair<int,int> pii;
  7. typedef pair<ll,ll> pll;
  8. typedef long double dbl;
  9.  
  10. #define fi first
  11. #define se second
  12. #define sz(a) ((int)a.size())
  13. #define pb push_back
  14.  
  15.  
  16. const int inf_int = 1e9;
  17. const int MAXN = 205;
  18. const int MX = 1e5+10;
  19.  
  20.  
  21. int cnt[MAXN];
  22. bool has[MAXN];
  23. void solve(){
  24. srand(time(0));
  25.  
  26. int n;
  27. cin >> n;
  28. cerr<<"new test "<<n<<endl;
  29. memset(cnt,0,sizeof cnt);
  30. memset(has,1,sizeof has);
  31.  
  32. for(int i=1;i<=n;++i){
  33. int d;
  34. cin >> d;
  35. cerr <<"d : "<<d<<endl;
  36. vector<int> ex;
  37. for(int e=1;e<=d;++e){
  38. int x;
  39. cin >> x;
  40. cnt[x]++;
  41. if(has[x]){
  42. ex.pb(x);
  43. }
  44. }
  45. if(sz(ex)==0){
  46. cout <<"-1"<<endl;
  47. cerr <<"output "<<-1<<endl;
  48. } else{
  49. int mn = inf_int;;
  50. for(int v:ex){
  51. mn = min(mn,cnt[v]);
  52. }
  53. vector<int> spec;
  54. for(int v:ex){
  55. if(cnt[v]==mn){
  56. spec.pb(v);
  57. }
  58. }
  59. random_shuffle(spec.begin(),spec.end());
  60. has[spec[0]] = 0;
  61. cout << spec[0]<<endl;
  62. cerr <<"output "<<spec[0]<<endl;
  63. }
  64.  
  65.  
  66. }
  67. cout.flush();
  68. }
  69.  
  70.  
  71. signed main(){
  72.  
  73. #ifdef zxc
  74. // freopen("input.txt","r",stdin);
  75. // freopen("output1.txt","w",stdout);
  76. #endif // zxc
  77.  
  78. /* ios_base::sync_with_stdio(0);
  79. cin.tie(0);
  80. cout.tie(0);*/
  81. int t = 1;
  82. cin >> t;
  83. for(int i=1;i<=t;++i){
  84. // cout <<"Case #"<<i<<": ";
  85. solve();
  86. }
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment