iscsi

codechef hypercube

Aug 4th, 2011
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <sstream>
  4. #include <string>
  5. #include <vector>
  6. #include <queue>
  7. #include <set>
  8. #include <map>
  9. #include <cstdio>
  10. #include <cstdlib>
  11. #include <cctype>
  12. #include <cmath>
  13. using namespace std;
  14. typedef long long LL;
  15. #define FOR(k,a,b) for(int k(a); k < (b); ++k)
  16. #define REP(k,a) for(int k=0; k < (a); ++k)
  17.  
  18. int calcBF(int x1, int x2, int y1, int y2)
  19. {
  20.     vector<vector<int> > v(x2+1,vector<int> (y2+1));
  21.     int res=0;
  22.     REP(i,v.size())
  23.     REP(j,v[0].size())
  24.     {
  25.         if(i && j)
  26.             v[i][j]=(v[i-1][j]+v[i][j-1])%2;
  27.         else
  28.             v[i][j]=1;
  29.         if(i>=x1 && j>=y1)
  30.             res+=v[i][j];
  31.     }
  32.     return res;
  33. }
  34.  
  35. int calc(int x,int y,const vector<int>& mv)
  36. {
  37.     if(!(x*y))
  38.         return 0;
  39.     if(x<y)
  40.         swap(x,y);
  41.     if(y==1)
  42.         return x;
  43.     int tmpy=0,tmpx=0;
  44.     while((1<<(tmpx+1))<=x)
  45.     {
  46.         ++tmpx;
  47.         if((1<<(tmpy+1))<=y)
  48.         {
  49.             ++tmpy;
  50.         }
  51.     }
  52.     int tt=mv[tmpy]*(1<<(tmpx-tmpy))+calc(y%(1<<tmpy),1<<tmpy,mv)*((1<<(tmpx-tmpy)))+calc(x%(1<<tmpy),1<<tmpy,mv);
  53.     if (tmpx!=tmpy)
  54.         tt+=calc(x%(1<<tmpy),y%(1<<tmpy),mv);
  55.     return tt;
  56.  
  57. }
  58.  
  59. int main()
  60. {
  61.     vector<int> third(1,1);
  62.     REP(i,20)
  63.     {
  64.         third.push_back(third.back()*3);
  65.     }
  66.     int res=calc(8,5,third);
  67.     cout << calcBF(0,8,0,4) << endl;
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment