Guest User

Untitled

a guest
Feb 16th, 2012
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. //SkyHawk, CMC MSU
  2.  
  3. #include <stdio.h>
  4. #include <iostream>
  5. #include <list>
  6. #include <string>
  7. #include <vector>
  8. #include <iterator>
  9. #include <algorithm>
  10. #include <cmath>
  11. #include <cstring>
  12. #include <set>
  13. #include <list>
  14. #include <queue>
  15.  
  16. using namespace std;
  17.  
  18. #define FOR(i,n) for(int i = 0;i < n;++i)
  19. #define PII pair<int,int>
  20. #define MIN(a,b) ((a)>(b)?(b):(a))
  21. #define MAX(a,b) ((a)>(b)?(a):(b))
  22.  
  23. int precalc[8][4] = {{0, 0, 0, 0},
  24. {1, 1, 1, 1},
  25. {0, 1, 0, 1},
  26. {0, 0, 1, 1},
  27. {0, 0, 0, 1},
  28. {0, 1, 2, 3},
  29. {0, 0, 1, 3},
  30. {0, 1, 2, 4}};
  31.  
  32. long long ar[4];
  33.  
  34. int main(int argc, char** argv)
  35. {
  36.     freopen("input.txt","r",stdin);
  37.     freopen("output.txt","w",stdout);
  38.     int n;
  39.     cin >> n;
  40.     if(n<=7)
  41.     {
  42.         FOR(i,4)
  43.             cout << precalc[n][i] << " ";
  44.         cout << endl;
  45.         return 0;
  46.     }
  47.     FOR(i,4)
  48.         ar[i] = precalc[7][i];
  49.     for(int i = 8;i<=n;++i)
  50.     {
  51.         long long x = abs(ar[3]-ar[1]-ar[2]);
  52.         if(x%2)
  53.         {
  54.             FOR(j,4)
  55.                 ar[j] = ar[j]*2;
  56.             x*=2;
  57.         }
  58.         x /=2;
  59.         long long t2 = x + ar[1] +x;
  60.         long long t3 = t2 + ar[2] + x;
  61.         ar[0] = 0;
  62.         ar[1] = x;
  63.         ar[2] = t2;
  64.         ar[3] = t3;
  65.     }
  66.     FOR(i,4)
  67.         cout << ar[i] << " ";
  68.     cout << endl;
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment