1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
#include <iostream> #include <cstdio> using namespace std; //no of 1' indicate how many times at least it lost a game //no of 0' indicate how many times at least it lost a game //so if a team id does not contain a 0 it can be the last of the tournament at it pessimist decision int NoOfRounds; int TeamNo; int TwosPower[31]; int main() { int t; int countOne; int countZero; scanf("%d",&t); TwosPower[0]=1; for(int i=1;i<31;i++) TwosPower[i]=TwosPower[i-1]<<1; while(t--) { scanf("%d%d",&NoOfRounds,&TeamNo); int tmp = TeamNo; countOne=0; while(tmp) { if(tmp%2) countOne+=1; tmp = tmp>>1; } //to find the worst case : after the first lost rest of the game can be considered as lost //so find the the first lost=first 1 from the left //from this we can find least number of winning match //subtract this from total number of matches of that tournaments. //each zero from the left means the team is better than the rest of the players of that round. tmp = TeamNo; countZero=0; int i=0; while(i<NoOfRounds) { if(tmp%2) break; else countZero+=TwosPower[i++]; tmp=tmp>>1; } printf("%d %d\n",countOne+1,TwosPower[NoOfRounds]-countZero); } return 0; } |