In Jollybee Chess Championship 2008, there are a number of players who have withdrawn themselves from the hampionship of 64 players (in this problem, we generalized it into 2 N players). Due to the nature of the competition, which is a regular knock-out tournament, and also the short notice of the withdrawals, some matches had been walkover matches (also known as a w/o, a victory due to the absent of the opponent).
If both players are available then there will be a normal match, one of them will advance to the next phase. If only one player is available then there will be a walkover match, and he/she will automatically advance. If no player is available then there will be no match.
In the right figure, the player #3 and #4 are withdrawn from the tournament, leaving a total of one w/o match (at match #3).
Given the list of players who withdraw right before the tournament start, calculate how many w/o matches to happen in the whole tournament, assuming that all of the remaining players play until the end of the tournament (winning or knocked-out).
Input
The first line of input contains an integer T, the number of test cases to follow. Each case begins with two integers, N (1 ≤ N ≤ 10) and M (0 ≤ M ≤ 2 N ). The next line contains M integers, denoting the players who have withdrawn themselves right before the tournament. The players are numbered from 1 to 2 N , ordered by their position in the tournament draw.
Output
For each case, print in a single line containing the number of walkover matches.
Sample Input
3
2 2
3 4
3 5
1 2 3 4 5
2 1
2
Sample Output
1
2
1
Regionals 2008 >> Asia - Jakarta
问题链接:UVA1241 LA4147 Jollybee Tournament
问题简述:(略)
问题分析:
简单的位操作有关的题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)
AC的C++语言程序如下:
/* UVA1241 LA4147 Jollybee Tournament */
#include <bits/stdc++.h>
using namespace std;
const int N = 1024; // 2^10
char c[N + 1];
int ans;
void compara(int i, char c[])
{
char a = c[i * 2] + c[i * 2 - 1];
if(a == 1)
c[i] = 1, ans++;
else
c[i] = a == 2 ? 1 : 0;
}
int main()
{
int t, n, m, a;
scanf("%d", &t);
while(t--) {
scanf("%d%d", &n, &m);
memset(c, 1, sizeof(c));
for(int i = 1; i <= m; i++) {
scanf("%d", &a);
c[a] = 0;
}
ans = 0;
while(n) {
int end = 1 << (n - 1);
for(int i = 1; i <= end; i++)
compara(i, c);
n--;
}
printf("%d\n", ans);
}
return 0;
}