pudakn

Bronze 2013 Nov - Combination Lock - no recursion

May 11th, 2026 (edited)
483
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //https://usaco.org/current/current/index.php?page=viewproblem2&cpid=340
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream cin("combo.in");
  7. ofstream cout("combo.out");
  8.  
  9. int v[4];
  10. int ans=0, N;
  11. int f1,f2,f3, m1,m2, m3;
  12.  
  13.  
  14. bool close(int a1,int a2,int a3,int b1,int b2,int b3){
  15.     if((abs(a1-b1)<=2 || abs(a1-b1)>=N-2)
  16.     && (abs(a2-b2)<=2 || abs(a2-b2)>=N-2)
  17.     && (abs(a3-b3)<=2 || abs(a3-b3)>=N-2))
  18.        
  19.         return true;
  20.        
  21.     return false;
  22. }
  23.  
  24. bool validLock(){
  25.     if(close(f1,f2,f3, v[1], v[2], v[3])) return true;
  26.  
  27.     if(close(m1,m2,m3, v[1], v[2], v[3])) return true;
  28.    
  29.     return false;
  30. }
  31.  
  32. int main()
  33. {
  34.     cin>>N;
  35.     cin>>f1>>f2>>f3>>m1>>m2>>m3;
  36.    
  37.     for(i1=1; i1<=N; i1++)
  38.         for(i2=1; i2<=N; i2++)
  39.             for(i3=1; i3<=N; i3++){
  40.                 v[1] = i1;
  41.                 v[2] = i2;
  42.                 v[3] = i3;
  43.                
  44.                 if(validLock())
  45.                     ans++;
  46.             }
  47.  
  48.     cout<<ans<<'\n';
  49.    
  50.     return 0;
  51. }
Advertisement