Guest User

Untitled

a guest
Feb 16th, 2012
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.94 KB | None | 0 0
  1. #pragma comment(linker,"/STACK:64000000")
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #include <iostream>
  4. #include <vector>
  5. #include <string>
  6. #include <sstream>
  7. #include <cmath>
  8. #include <map>
  9. #include <set>
  10. #include <ctime>
  11. #include <algorithm>
  12. #include <memory.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15.  
  16. using namespace std;
  17.  
  18. #define WR printf
  19. #define RE scanf
  20. #define PB push_back
  21. #define SE second
  22. #define FI first
  23.  
  24. #define FOR(i,k,n) for(int i=(k); i<=(n); i++)
  25. #define DFOR(i,k,n) for(int i=(k); i>=(n); i--)
  26. #define SZ(a) (int)((a).size())
  27. #define FA(i,v) FOR(i,0,SZ(v)-1)
  28. #define RFA(i,v) DFOR(i,SZ(v)-1,0)
  29. #define CLR(a) memset(a, 0, sizeof(a))
  30.  
  31. #define LL long long
  32. #define VI  vector<int>
  33. #define PAR pair<int ,int>
  34. #define o_O 1000000000
  35.  
  36. void __never(int a){printf("\nOPS %d", a);}
  37. #define ass(s) {if (!(s)) {__never(__LINE__);cout.flush();cerr.flush();abort();}}
  38.  
  39. bool F[128];
  40. int ans[128][4];
  41.  
  42. int check(int a, int b, int c, int d)
  43. {
  44.     int re=0;
  45.     while(1)
  46.     {
  47.         if (a+b+c+d==0) return re;
  48.         if (re==200) return -1;
  49.         int aa = abs(a-b), bb = abs(b-c), cc = abs(c-d), dd = abs(d-a);
  50.         a = aa; b = bb; c = cc; d = dd;
  51.         re++;
  52.     }
  53.     return -1;
  54. }
  55.  
  56. void sol()
  57. {
  58.     FOR(a,0,0) FOR(b,0,1000)
  59.     {
  60.         FOR(c,b,5000) FOR(d,c,20000)
  61.         {
  62.             int x = check(a,b,c,d);
  63.             if (x>=0 && !F[x])
  64.             {
  65.                 F[x]=true;
  66.                 //WR("%d %d %d %d  %d\n", a, b, c, d, x );
  67.                 ans[x][0] = a;
  68.                 ans[x][1] = b;
  69.                 ans[x][2] = c;
  70.                 ans[x][3] = d;
  71.             }
  72.         }
  73.         cerr << a << " " << b << "\n";
  74.     }
  75.  
  76.     FOR(a,0,100) if (F[a])
  77.     {
  78.         FOR(b,0,3) WR("%d ", ans[a][b]);
  79.         WR(" %d\n", a);
  80.     }
  81. }
  82.  
  83. void sol2(int i)
  84. {
  85.     if (i==0) cout << "0 0 0 0\n";
  86.     else if (i==1) cout << "1 1 1 1\n";
  87.     else if (i==2) cout << "0 1 0 1\n";
  88.     else if (i==3) cout << "0 0 1 1\n";
  89.     else if (i==4) cout << "0 0 0 1\n";
  90.     else if (i==5) cout << "0 1 2 3\n";
  91.     else if (i==6) cout << "0 0 1 3\n";
  92.     else if (i==7) cout << "0 1 2 4\n";
  93.     else if (i==8) cout << "0 1 4 9\n";
  94.     else if (i==9) cout << "0 2 5 11\n";
  95.     else
  96.     {
  97.         LL A=2, B=3, C=6, D=11;
  98.         LL z=0;
  99.         FOR(a,10,i)
  100.         {
  101.             if (a%3==2)
  102.             {
  103.                 A*=2;
  104.                 B*=2;
  105.                 C*=2;
  106.                 D*=2;
  107.                 z=(LL)((double)z*2.3829757679); // magic
  108.             }
  109.             else z=(LL)((double)z*1.191487883953); // another magic
  110.             while(1)
  111.             {
  112.                 LL aa = A+z;
  113.                 LL bb = A+aa;
  114.                 LL cc = B+bb;
  115.                 LL dd = C+cc;
  116.                 if (aa>0 && bb>=0 && cc>=0 && dd>=0 && dd-aa==D)
  117.                 {
  118.                     LL aaa = 0;
  119.                     LL bbb = aa;
  120.                     LL ccc = bbb + bb;
  121.                     LL ddd = ccc + cc;
  122.                     if (ddd == dd)
  123.                     {
  124.                         if (a==i)
  125.                         {
  126.                             //cerr << a << "\n";
  127.                             cout << aaa << " " << bbb << " " << ccc << " " << ddd << "\n";
  128.                             //cout.flush();
  129.                             return;
  130.                         }
  131.                         A = aa;
  132.                         B = bb;
  133.                         C = cc;
  134.                         D = dd;
  135.                         break;
  136.                     }
  137.                 }
  138.                 z++;
  139.             }
  140.         }
  141.     }
  142. }
  143.  
  144. int main()
  145. {
  146.     freopen("input.txt","r",stdin);
  147.     freopen("output.txt","w",stdout);
  148.  
  149.     int n;
  150.     cin >> n;
  151.     sol2(n);
  152.     //FOR(a,0,100) sol2(a);
  153.  
  154.     //sol();
  155.     return 0;
  156. }
Advertisement
Add Comment
Please, Sign In to add comment