Direct impersonation will time out
1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 Const intmaxx= +;6 intD,n;7 BOOLf[1<<Maxx];8 intMain ()9 {Ten intT; Onescanf"%d",&T); A while(t--) - { -Memset (F,0,sizeof(f)); thescanf"%d%d",&d,&n); - for(intI=1; i<=n;i++) - { - intp=1; + for(intj=1; j<d;j++) - { + if(f[p]==0) A { atf[p]=1; -p=p*2; - } - Else - { -f[p]=0; inp=p*2+1; - } to } + if(i==n) printf ("%d\n", p); - } the } *scanf"%d",&T); $}
You can see the last ball directly, and look at the parity.
1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 intD,n;6 intMain ()7 {8 intT;9scanf"%d",&T);Ten while(t--) One { Ascanf"%d%d",&d,&n); - intp=1; - for(intI=1; i<d;i++) the { - if(n%2==1) p=p*2; - Elsep=p*2+1; -N= (n+1)/2; + } -printf"%d\n", p); + } Ascanf"%d",&T); at}
Uva-679-dropping Balls