Last active
January 1, 2016 23:39
-
-
Save KT-Yeh/8218134 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cmath> | |
using namespace std; | |
typedef long long int llt; | |
llt round(llt x){ //Team x到達哪個Round(在哪個Round 輸掉) | |
for(llt i=1,j=1;;i*=2,j++) | |
if(x%i) return j-1; | |
} | |
llt win(llt x){ //贏Team x的Team | |
return x-pow(2,round(x)-1); | |
} | |
llt optimistic(llt n,llt x){ | |
if (x==0) return 1; | |
llt num=0; //贏Team X的隊數 | |
while(1){ | |
x=win(x); | |
num++; | |
if(x==0) break; | |
} | |
return num+1; | |
} | |
llt pessimistic(llt n,llt x){ | |
if (x==0) return 1; | |
llt all=pow(2,n); | |
llt numOfx_worse=pow(2,round(x)-1)-1; //比Team x差的隊數 | |
return all-numOfx_worse; | |
} | |
int main() | |
{ | |
llt M,N,X; | |
scanf("%lld",&M); | |
while(M--){ | |
scanf("%lld %lld",&N,&X); | |
printf("%lld %lld\n",optimistic(N,X),pessimistic(N,X)); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment