Codechef July 2014 Long Contest - RETPO - reach the point editorial: http://discuss.codechef.com/questions/47238/retpo-editorial
Codechef July 2014 Long Contest - RETPO - reach the point solution: http://ideone.com/gu1gDi
#include <iostream> #include <cstdio> #include <cstdlib> using namespace std; int main() { int t, x, y; long long cnt; scanf("%d", &t); while(t--) { cnt=0; scanf("%d%d", &x, &y); x=abs(x), y=abs(y); while(x>0 && y>0) { cnt+=min(x, y), cnt<<=1; if(x<y) y-=x, x=0; else x-=y, y=0; } if(x==0 && y>0) { if(y%2==0) y<<=1; else y<<=1, y--; cnt+=y; } else if(y==0 && x>0) { if(x%2==0) x<<=1; else x<<=1, x++; cnt+=x; } printf("%lld\n", cnt); } return 0; }
No comments:
Post a Comment