fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. typedef pair < int , int > Point;
  5. typedef pair < Point,int > iii;
  6. vector < iii > Comb;
  7.  
  8.  
  9. int main()
  10. {
  11. freopen("this.in","r+",stdin);
  12. freopen("that.txt","w+",stdout);
  13. int T;
  14. scanf("%d",&T);
  15. for(int e=1;e<=T;++e)
  16. {
  17. cout<<"Case #"<<e<<": ";
  18. Comb.clear();
  19. int J , P , S , K , i , k , l ;
  20. cin>>J>>P>>S>>K;
  21.  
  22. for(i=1;i<=J;++i)
  23. for(k=1;k<=P;++k)
  24. for(l=1;l<=S;++l)
  25. Comb.push_back({{i,k},l});
  26.  
  27. int high = 0 , idx = 0;
  28.  
  29. for(i=1;i<(1LL<<Comb.size());++i)
  30. {
  31. if(__builtin_popcount(i)<=high)
  32. continue;
  33.  
  34. int M1[4][4]={0};
  35. int M2[4][4]={0};
  36. int M3[4][4]={0};
  37.  
  38. int flag = 0;
  39. for(int j=0;j<(int)Comb.size();++j)
  40. {
  41. if((i>>j)&1)
  42. {
  43. M1[Comb[j].first.first][Comb[j].first.second]++; // 1 2
  44. M2[Comb[j].first.first][Comb[j].second]++; // 1 3
  45. M3[Comb[j].first.second][Comb[j].second]++; // 2 3
  46. if(M1[Comb[j].first.first][Comb[j].first.second]>K || M2[Comb[j].first.first][Comb[j].second]>K || M3[Comb[j].first.second][Comb[j].second]>K)
  47. {
  48. flag =1;
  49. break;
  50. }
  51. }
  52. }
  53. if(flag)continue;
  54. high = __builtin_popcount(i);
  55. idx = i;
  56. }
  57.  
  58.  
  59. cout<<high<<'\n';
  60. i = idx;
  61. for(int j=0;j<(int)Comb.size();++j)
  62. {
  63. if((i>>j)&1)
  64. cout<<Comb[j].first.first<<" "<<Comb[j].first.second<<" "<<Comb[j].second<<"\n";
  65. }
  66.  
  67. }
  68. return 0;
  69. }
  70.  
Success #stdin #stdout 0s 3460KB
stdin
1 1 1 1 1
stdout
Standard output is empty