 A.Problem 2102 Solve equation
 A.Problem 2102 Solve equation Problem Description
 Problem DescriptionYou are given two positive integers A and B in Base C. For the equation:
We know there always existing many non-negative pairs (k, d) that satisfy the equation above. Now in this problem, we want to maximize k.
For example, A="123" and B="100", C=10. So both A and B are in Base 10. Then we have:
(1) A=0*B+123
(2) A=1*B+23
As we want to maximize k, we finally get one solution: (1, 23)
The range of C is between 2 and 16, and we use ‘a‘, ‘b‘, ‘c‘, ‘d‘, ‘e‘, ‘f‘ to represent 10, 11, 12, 13, 14, 15, respectively.
 Input
 InputThe first line of the input contains an integer T (T≤10), indicating the number of test cases.
Then T cases, for any case, only 3 positive integers A, B and C (2≤C≤16) in a single line. You can assume that in Base 10, both A and B is less than 2^31.
 Output
 Output Sample Input
 Sample Input Sample Output
 Sample Output Source
 Source#include <queue>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define FIN             freopen("input.txt","r",stdin)
#define FOUT            freopen("output.txt","w",stdout)
#define fst             first
#define snd             second
typedef __int64  LL;
typedef pair<int, int> PII;
const double eps = 1e-10;
const int MAXN = 1e2 + 5;
const int INF  = 0x3f3f3f3f;
int T, N, M;
int c;
char a[MAXN], b[MAXN];
int get(char* s)
{
    int t = 1, res = 0, len = strlen(s);;
    for (int i = len - 1; i >= 0; i--, t *= c) {
        if (s[i] >= 'a' && s[i] <= 'z')
            res += (s[i] - 'a' + 10) * t;
        else
            res += (s[i] - '0') * t;
    }
    return res;
}
int main() {
#ifndef ONLINE_JUDGE
     FIN;
    // FOUT;
#endif // ONLINE_JUDGE
    int cas = 0, res;
    scanf("%d", &T);
    while (T--) {
        scanf("%s%s%d", a, b, &c);
        int aa = get(a);
        int bb = get(b);
        printf("(%d,%d)\n", aa / bb, aa % bb);
    }
    return 0;
} C.Problem 2104 Floor problem
 C.Problem 2104 Floor problem Problem Description
 Problem DescriptionIn this problem, we have f(n,x)=Floor[n/x]. Here Floor[x] is the biggest integer such that no larger than x. For example, Floor[1.1]=Floor[1.9]=1, Floor[2.0]=2.
You are given 3 positive integers n, L and R. Print the result of f(n,L)+f(n,L+1)+...+f(n,R), please.
 Input
 InputThe first line of the input contains an integer T (T≤100), indicating the number of test cases.
Then T cases, for any case, only 3 integers n, L and R (1≤n, L, R≤10,000, L≤R).
 Output
 Output Sample Input
 Sample Input Sample Output
 Sample Output Source
 Source#include <queue>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define FIN             freopen("input.txt","r",stdin)
#define FOUT            freopen("output.txt","w",stdout)
#define fst             first
#define snd             second
typedef __int64  LL;
typedef pair<int, int> PII;
const double eps = 1e-10;
const int MAXN = 1e7 + 5;
const int INF  = 0x3f3f3f3f;
int T, N, M;
int main() {
#ifndef ONLINE_JUDGE
    FIN;
    // FOUT;
#endif // ONLINE_JUDGE
    int cas = 0, res;
    int L, R;
    scanf ("%d", &T);
    while (T --) {
        res = 0;
        scanf ("%d %d %d", &N, &L, &R);
        for (int i = L; i <= R; i++) {
            res += N / i;
        }
        printf ("%d\n", res);
    }
    return 0;
}
 F.Problem 2107 Hua Rong Dao
 F.Problem 2107 Hua Rong Dao Problem Description
 Problem DescriptionCao Cao was hunted down by thousands of enemy soldiers when he escaped from Hua Rong Dao. Assuming Hua Rong Dao is a narrow aisle (one N*4 rectangle), while Cao Cao can be regarded as one 2*2 grid. Cross general can be regarded as one 1*2 grid.Vertical general can be regarded as one 2*1 grid. Soldiers can be regarded as one 1*1 grid. Now Hua Rong Dao is full of people, no grid is empty.
There is only one Cao Cao. The number of Cross general, vertical general, and soldier is not fixed. How many ways can all the people stand?
 Input
 InputThere is a single integer T (T≤4) in the first line of the test data indicating that there are T test cases.
Then for each case, only one integer N (1≤N≤4) in a single line indicates the length of Hua Rong Dao.
 Output
 Output Sample Input
 Sample Input Sample Output
 Sample Output Hint
 HintHere are 2 possible ways for the Hua Rong Dao 2*4.
 
 Source
 Source#include <queue>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define FIN             freopen("input.txt","r",stdin)
#define FOUT            freopen("output.txt","w",stdout)
#define fst             first
#define snd             second
typedef __int64  LL;
typedef pair<int, int> PII;
const double eps = 1e-10;
const int MAXN = 1e7 + 5;
const int INF  = 0x3f3f3f3f;
int T, N, M;
LL ans = 0;
bool cc, vis[5][5];
void dfs (int x, int y) {
	if (x == N) {
		if (!cc)
			ans++;
		return;
	}
	int xx = x, yy = y + 1;
	if (yy > 3) {
		xx++;
		yy = 0;
	}
	if (vis[x][y]) {
		dfs (xx, yy);
	} else {
		for (int i = 0; i < 4; i++) {
			if (i == 0) { // 2 * 2
				if (!cc)
					continue;
				else {
					if (x + 1 < N && y + 1 < 4 && !vis[x + 1][y] && !vis[x][y + 1] && !vis[x + 1][y + 1]) {
						cc = false;
						vis[x][y] = vis[x + 1][y] = vis[x][y + 1] = vis[x + 1][y + 1] = true;
						dfs (xx, yy);
						cc = true;
						vis[x][y] = vis[x + 1][y] = vis[x][y + 1] = vis[x + 1][y + 1] = false;
					}
				}
			} else if (i == 1) { // 2 * 1
				if (x + 1 < N && !vis[x + 1][y]) {
					vis[x][y] = vis[x + 1][y] = true;
					dfs (xx, yy);
					vis[x][y] = vis[x + 1][y] = false;
				}
			} else if (i == 2) { // 1 * 2
				if (y + 1 < 4 && !vis[x][y + 1]) {
					vis[x][y] = vis[x][y + 1] = true;
					dfs (xx, yy);
					vis[x][y] = vis[x][y + 1] = false;
				}
			} else if (i == 3) { // 1 * 1
				vis[x][y] = true;
				dfs (xx, yy);
				vis[x][y] = false;
			}
		}
	}
}
int main() {
#ifndef ONLINE_JUDGE
	FIN;
	// FOUT;
#endif // ONLINE_JUDGE
	int cas = 0, res, ans[5] = {0, 0, 18, 284, 4862};
	scanf("%d", &T);
	while (T--) {
		scanf("%d", &N);
		printf("%d\n", ans[N]);
	}
	return 0;
}<span style="font-size:12px;">
</span>
 Problem Description
 Problem DescriptionGiven one non-negative integer A and one positive integer B, it’s very easy for us to calculate A Mod B. Here A Mod B means the remainder of the answer after A is divided by B. For example, 7 Mod 5 = 2, 12 Mod 3 = 0, 0 Mod 3 = 0.
In this problem, we use the following rules to express A.
(1) One non-empty string that only contains {0,1,2,3,4,5,6,7,8,9} is valid.
For example, 123, 000213, 99213. (Leading zeros is OK in this problem)
(2) If w is valid, then [w]x if valid. Here x is one integer that 0<x<10.
For example, [012]2=012012, [35]3[7]1=3535357.
(3) If w and v are valid, then wv is valid.
For example, w=[231]2 and v=1, then wv=[231]21 is valid (which is 2312311).
Now you are given A and B. Here A is express as the rules above and B is simply one integer, you are expected to output the A Mod B.
 Input
 InputThe first line of the input contains an integer T(T≤10), indicating the number of test cases.
Then T cases, for any case, only two lines.
The first line is one non-empty and valid string that expresses A, the length of the string is no more than 1,000.
The second line is one integer B(0<B<2,000,000,000).
You may assume that the length of number A in decimal notation will less than 2^63.
 Output
 Output Sample Input
 Sample Input Sample Output
 Sample Output Source
 Source/*头文件模板*/
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <cctype>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iomanip>
#include <typeinfo>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define pb push_back
#define mp make_pair
#define mem(a, x) memset(a, x, sizeof(a))
#define copy(a, b) memcpy(a, b, sizeof(a))
#define lson rt << 1, l, mid
#define rson rt << 1|1, mid + 1, r
#define FIN freopen("input.txt", "r", stdin)
#define FOUT freopen("output.txt", "w", stdout)
typedef long long LL;
typedef pair<int, int > PII;
typedef pair<int, string> PIS;
typedef pair<LL, int>PLI;
typedef pair<LL, LL>PLL;
typedef unsigned long long uLL;
template<typename T>
void print (T* p, T* q, string Gap = " ", bool flag = false) {
	int d = p < q ? 1 : -1;
	while (p != q) {
		if (flag) cout << Gap[0] << *p << Gap[1];
		else cout << *p;
		p += d;
		if (p != q && !flag) cout << Gap;
	}
	cout << endl;
}
template<typename T>
void print (const T &a, string bes = "") {
	int len = bes.length();
	if (len >= 2) cout << bes[0] << a << bes[1] << endl;
	else cout << a << endl;
}
template<typename T>
void debug (T* p, T* q, string Gap = " ", bool flag = false) {
#ifndef ONLINE_JUDGE
	int d = p < q ? 1 : -1;
	cout << "Debug out : ";
	while (p != q) {
		if (flag) cout << Gap[0] << *p << Gap[1];
		else cout << *p;
		p += d;
		if (p != q && !flag) cout << Gap;
	}
	cout << endl;
#endif
}
template<typename T>
void debug (const T &a, string bes = "") {
#ifndef ONLINE_JUDGE
	int len = bes.length();
	cout << "Debug out : ";
	if (len >= 2) cout << bes[0] << a << bes[1] << endl;
	else cout << a << endl;
#endif
}
void IO_Init() {
	ios::sync_with_stdio (false);
}
LL LLabs (const LL a) {
	return a >= 0 ? a : -a;
}
const double PI = 3.1415926535898;
const double eps = 1e-10;
const int MAXM = 1e5 + 5;
const int MAXN = 1e3 + 5;
const int INF = 0x3f3f3f3f;
/*头文件模板*/
int T, slen;
char A[MAXN];
LL b;
stack<char>C;
LL mod_pow(LL x, int p, LL mod) {
	LL ret = 1;
	while(p > 0) {
		if(p & 1) ret = ret * x % mod;
		x = x * x % mod;
		p >>= 1;
	}
	return ret;
}
PLI solve(int &l) {
	int cnt = 0,len = 0;
	LL ans = 0;
	while(l < slen) {
		if(A[l] == '[') {
			int r = ++ l;
			PLI a = solve(r);
			int k = A[r + 1] - '0';
			for(int i = 0; i < k; i ++) {
				ans = (ans * mod_pow(10, a.second, b) % b + a.first) % b;
			}
			len += k * a.second;
			l = r + 2;
		} else if(A[l] == ']') {
			break;
		} else {
			ans = (ans * 10 % b + A[l ++] - '0') % b;
			len ++;
		}
	}
	return PLI(ans, len);
}
int main() {
#ifndef ONLINE_JUDGE
	//FIN;
	//FOUT;
#endif
	IO_Init();
	scanf("%d", &T);
	while(T --) {
		scanf("%s%I64d", A, &b);
		slen = strlen(A);
		int k = 0;
		printf("%I64d\n", solve(k).first);
	}
	return 0;
}
 H.Problem 2109 Mountain Number
 H.Problem 2109 Mountain Number Problem Description
 Problem DescriptionOne integer number x is called "Mountain Number" if:
(1) x>0 and x is an integer;
(2) Assume x=a[0]a[1]...a[len-2]a[len-1](0≤a[i]≤9, a[0] is positive). Any a[2i+1] is larger or equal to a[2i] and a[2i+2](if exists).
For example, 111, 132, 893, 7 are "Mountain Number" while 123, 10, 76889 are not "Mountain Number".
Now you are given L and R, how many "Mountain Number" can be found between L and R (inclusive) ?
 Input
 InputThe first line of the input contains an integer T (T≤100), indicating the number of test cases.
Then T cases, for any case, only two integers L and R (1≤L≤R≤1,000,000,000).
 Output
 Output Sample Input
 Sample Input Sample Output
 Sample Output Source
 Source/*头文件模板*/
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <vector>
#include <cctype>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iomanip>
#include <typeinfo>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define pb push_back
#define mp make_pair
#define mem(a, x) memset(a, x, sizeof(a))
#define copy(a, b) memcpy(a, b, sizeof(a))
#define lson rt << 1, l, mid
#define rson rt << 1|1, mid + 1, r
#define FIN freopen("input.txt", "r", stdin)
#define FOUT freopen("output.txt", "w", stdout)
typedef long long LL;
typedef pair<int, int > PII;
typedef pair<int, string> PIS;
typedef pair<LL, LL>PLL;
typedef unsigned long long uLL;
template<typename T>
void print (T* p, T* q, string Gap = " ", bool flag = false) {
    int d = p < q ? 1 : -1;
    while (p != q) {
        if (flag) cout << Gap[0] << *p << Gap[1];
        else cout << *p;
        p += d;
        if (p != q && !flag) cout << Gap;
    }
    cout << endl;
}
template<typename T>
void print (const T &a, string bes = "") {
    int len = bes.length();
    if (len >= 2) cout << bes[0] << a << bes[1] << endl;
    else cout << a << endl;
}
template<typename T>
void debug (T* p, T* q, string Gap = " ", bool flag = false) {
    int d = p < q ? 1 : -1;
    cout << "Debug out : ";
    while (p != q) {
        if (flag) cout << Gap[0] << *p << Gap[1];
        else cout << *p;
        p += d;
        if (p != q && !flag) cout << Gap;
    }
    cout << endl;
}
template<typename T>
void debug (const T &a, string bes = "") {
    int len = bes.length();
    cout << "Debug out : ";
    if (len >= 2) cout << bes[0] << a << bes[1] << endl;
    else cout << a << endl;
}
void IO_Init() {
    ios::sync_with_stdio (false);
}
LL LLabs (const LL a) {
    return a >= 0 ? a : -a;
}
const double PI = 3.1415926535898;
const double eps = 1e-10;
const int MAXM = 1e5 + 5;
const int MAXN = 32000 + 5;
const int INF = 0x3f3f3f3f;
/*头文件模板*/
LL dp[20][10][2];
int bit[20];
LL dfs (int pos, int pre, int z, int odd, int limit) {
    if (pos < 0) return 1;
    if (!limit && dp[pos][pre][odd] != -1)
        return  dp[pos][pre][odd];
    int ends = limit ? bit[pos] : 9;
    LL ret = 0;
    for (int i = 0; i <= ends; i ++)
        if (z) {
            ret += dfs (pos - 1, i, 0, !odd, limit && (i == ends) );
        } else if (odd && pre <= i) {
            ret += dfs (pos - 1, i, 0, !odd, limit && (i == ends) );
        } else if (!odd && pre >= i) {
            ret += dfs (pos - 1, i, 0, !odd, limit && (i == ends) );
        }
    if (!limit)
        dp[pos][pre][odd] = ret;
    return ret;
}
void init() {
    mem (dp, -1);
}
LL solve (int x) {
    int len = 0;
    while (x) {
        bit[len ++] = x % 10;
        x /= 10;
    }
    return dfs (len - 1, 9, 1, 0, 1);
}
int main() {
#ifndef ONLINE_JUDGE
    //FIN;
    //FOUT;
#endif
    IO_Init();
    int T;
    scanf ("%d", &T);
    int l, r;
    while (T --) {
        init();
        scanf ("%d%d", &l, &r);
        printf ("%I64d\n", solve (r) - solve (l - 1) );
    }
    return 0;
} I.Problem 2110 Star
 I.Problem 2110 Star Problem Description
 Problem Description Input
 InputThe first line of the input contains an integer T (T≤10), indicating the number of test cases.
For each test case:
The first line contains one integer n (1≤n≤100), the number of stars.
The next n lines each contains two integers x and y (0≤|x|, |y|≤1,000,000) indicate the points, all the points are distinct.
 Output
 Output Sample Input
 Sample Input Sample Output
 Sample Output Source
 Source#include <queue>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define FIN             freopen("input.txt","r",stdin)
#define FOUT            freopen("output.txt","w",stdout)
#define fst             first
#define snd             second
typedef __int64  LL;
typedef pair<int, int> PII;
const double eps = 1e-10;
const int MAXN = 1e2 + 5;
const int INF  = 0x3f3f3f3f;
int T, N, M, x[MAXN], y[MAXN];
bool judge(int x2, int y2, int x3, int y3, int x4, int y4)
{
    LL a = (LL)(x2 - x3) * (x2 - x3) + (LL)(y2 - y3) * (y2 - y3);
    LL b = (LL)(x2 - x4) * (x2 - x4) + (LL)(y2 - y4) * (y2 - y4);
    LL c = (LL)(x4 - x3) * (x4 - x3) + (LL)(y4 - y3) * (y4 - y3);
    return (a < b + c) && (b < a + c) && (c < a + b);
}
int main() {
#ifndef ONLINE_JUDGE
     FIN;
    // FOUT;
#endif // ONLINE_JUDGE
    int cas = 0, res;
    scanf("%d", &T);
    while (T--) {
        scanf("%d", &N);
        for (int i = 0; i < N; i++)
            scanf("%d%d", &x[i], &y[i]);
        int cnt = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                for (int k = j + 1; k < N; k++) {
                    if (judge(x[i], y[i], x[j], y[j], x[k], y[k]))
                        cnt++;
                }
            }
        }
        printf("%d\n", cnt);
;    }
    return 0;
} J.Problem 2111 Min Number
 J.Problem 2111 Min Number Problem Description
 Problem DescriptionNow you are given one non-negative integer n in 10-base notation, it will only contain digits (‘0‘-‘9‘). You are allowed to choose 2 integers i and j, such that: i!=j, 1≤i<j≤|n|, here |n| means the length of n’s 10-base notation. Then we can swap n[i] and n[j].
For example, n=9012, we choose i=1, j=3, then we swap n[1] and n[3], then we get 1092, which is smaller than the original n.
Now you are allowed to operate at most M times, so what is the smallest number you can get after the operation(s)?
Please note that in this problem, leading zero is not allowed!
 Input
 InputThe first line of the input contains an integer T (T≤100), indicating the number of test cases.
Then T cases, for any case, only 2 integers n and M (0≤n<10^1000, 0≤M≤100) in a single line.
 Output
 Output Sample Input
 Sample Input Sample Output
 Sample Output Source
 Source#include <queue>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define FIN             freopen("input.txt","r",stdin)
#define FOUT            freopen("output.txt","w",stdout)
#define fst             first
#define snd             second
typedef __int64  LL;
typedef pair<int, int> PII;
const double eps = 1e-10;
const int MAXN = 1000 + 5;
const int INF  = 0x3f3f3f3f;
int T, N, M;
char buf[MAXN];
int main() {
#ifndef ONLINE_JUDGE
    FIN;
    // FOUT;
#endif // ONLINE_JUDGE
    int cas = 0, res, b;
    scanf ("%d", &T);
    while (T --) {
        scanf ("%s %d", buf, &M);
        int len = strlen (buf);
        if (!M) {
            printf ("%s\n", buf);
            continue;
        }
        b = -1;
        if (buf[0] >= '2') {
            for (int j = len - 1; j > 0; j--) {
                if (buf[j] == '0') continue;
                if (buf[j] >= buf[0]) continue;
                if (b == -1 || buf[b] > buf[j]) {
                    b = j;
                }
            }
            if (b != -1) {
                swap (buf[b], buf[0]);
                M --;
            }
        }
        for (int k = 0, i = 1; k < M && i < len; i++) {
            b = -1;
            for (int j = len - 1; j > i; j --) {
                if (buf[j] >= buf[i]) continue;
                if (b == -1 || buf[b] > buf[j]) {
                    b = j;
                }
            }
            if (b != -1) {
                swap (buf[i], buf[b]);
                k ++;
            }
        }
        printf ("%s\n", buf);
    }
    return 0;
}
 K.Problem 2112 Tickets
 K.Problem 2112 Tickets Problem Description
 Problem DescriptionYou have won a collection of tickets on luxury cruisers. Each ticket can be used only once, but can be used in either direction between the 2 different cities printed on the ticket. Your prize gives you free airfare to any city to start your cruising, and free airfare back home from wherever you finish your cruising.
You love to sail and don‘t want to waste any of your free tickets. How many additional tickets would you have to buy so that your cruise can use all of your tickets?
Now giving the free tickets you have won. Please compute the smallest number of additional tickets that can be purchased to allow you to use all of your free tickets.
 Input
 InputThere is one integer T (T≤100) in the first line of the input.
Then T cases, for any case, the first line contains 2 integers n, m (1≤n, m≤100,000). n indicates the identifier of the cities are between 1 and n, inclusive. m indicates the tickets you have won.
Then following m lines, each line contains two integers u and v (1≤u, v≤n), indicates the 2 cities printed on your tickets, respectively.
 Output
 Output Sample Input
 Sample Input Sample Output
 Sample Output Source
 Source/*头文件模板*/
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <cctype>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iomanip>
#include <typeinfo>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define pb push_back
#define mp make_pair
#define mem(a, x) memset(a, x, sizeof(a))
#define copy(a, b) memcpy(a, b, sizeof(a))
#define lson rt << 1, l, mid
#define rson rt << 1|1, mid + 1, r
#define FIN freopen("input.txt", "r", stdin)
#define FOUT freopen("output.txt", "w", stdout)
typedef long long LL;
typedef pair<int, int > PII;
typedef pair<int, string> PIS;
typedef pair<LL, LL>PLL;
typedef unsigned long long uLL;
template<typename T>
void print (T* p, T* q, string Gap = " ", bool flag = false) {
	int d = p < q ? 1 : -1;
	while (p != q) {
		if (flag) cout << Gap[0] << *p << Gap[1];
		else cout << *p;
		p += d;
		if (p != q && !flag) cout << Gap;
	}
	cout << endl;
}
template<typename T>
void print (const T &a, string bes = "") {
	int len = bes.length();
	if (len >= 2) cout << bes[0] << a << bes[1] << endl;
	else cout << a << endl;
}
template<typename T>
void debug (T* p, T* q, string Gap = " ", bool flag = false) {
#ifndef ONLINE_JUDGE
	int d = p < q ? 1 : -1;
	cout << "Debug out : ";
	while (p != q) {
		if (flag) cout << Gap[0] << *p << Gap[1];
		else cout << *p;
		p += d;
		if (p != q && !flag) cout << Gap;
	}
	cout << endl;
#endif
}
template<typename T>
void debug (const T &a, string bes = "") {
#ifndef ONLINE_JUDGE
	int len = bes.length();
	cout << "Debug out : ";
	if (len >= 2) cout << bes[0] << a << bes[1] << endl;
	else cout << a << endl;
#endif
}
void IO_Init() {
	ios::sync_with_stdio (false);
}
LL LLabs (const LL a) {
	return a >= 0 ? a : -a;
}
const double PI = 3.1415926535898;
const double eps = 1e-10;
const int MAXM = 1e5 + 5;
const int MAXN = 1e5 + 5;
const int INF = 0x3f3f3f3f;
/*头文件模板*/
int n, m;
int d[MAXN];
int main() {
#ifndef ONLINE_JUDGE
	//FIN;
	//FOUT;
#endif
	IO_Init();
	int T, u, v;
	scanf("%d", &T);
	while(T --) {
		mem(d, 0);
		scanf("%d%d", &n, &m);
		for(int i = 0; i < m; i ++) {
			scanf("%d%d", &u, &v);
			d[v] ++;
			d[u] ++;
		}
		int ans = 0;
		for(int i = 1; i <= n; i ++) {
			if(d[i] & 1) ans ++;
		}
		if(ans <= 2) {
			ans = 0;
		} else {
			ans = (ans - 2) / 2;
		}
		printf("%d\n", ans);
	}
	return 0;
}/*头文件模板*/
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <cctype>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iomanip>
#include <typeinfo>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define pb push_back
#define mp make_pair
#define mem(a, x) memset(a, x, sizeof(a))
#define copy(a, b) memcpy(a, b, sizeof(a))
#define lson rt << 1, l, mid
#define rson rt << 1|1, mid + 1, r
#define FIN freopen("input.txt", "r", stdin)
#define FOUT freopen("output.txt", "w", stdout)
typedef long long LL;
typedef pair<int, int > PII;
typedef pair<int, string> PIS;
typedef pair<LL, LL>PLL;
typedef unsigned long long uLL;
template<typename T>
void print (T* p, T* q, string Gap = " ", bool flag = false) {
	int d = p < q ? 1 : -1;
	while (p != q) {
		if (flag) cout << Gap[0] << *p << Gap[1];
		else cout << *p;
		p += d;
		if (p != q && !flag) cout << Gap;
	}
	cout << endl;
}
template<typename T>
void print (const T &a, string bes = "") {
	int len = bes.length();
	if (len >= 2) cout << bes[0] << a << bes[1] << endl;
	else cout << a << endl;
}
template<typename T>
void debug (T* p, T* q, string Gap = " ", bool flag = false) {
#ifndef ONLINE_JUDGE
	int d = p < q ? 1 : -1;
	cout << "Debug out : ";
	while (p != q) {
		if (flag) cout << Gap[0] << *p << Gap[1];
		else cout << *p;
		p += d;
		if (p != q && !flag) cout << Gap;
	}
	cout << endl;
#endif
}
template<typename T>
void debug (const T &a, string bes = "") {
#ifndef ONLINE_JUDGE
	int len = bes.length();
	cout << "Debug out : ";
	if (len >= 2) cout << bes[0] << a << bes[1] << endl;
	else cout << a << endl;
#endif
}
void IO_Init() {
	ios::sync_with_stdio (false);
}
LL LLabs (const LL a) {
	return a >= 0 ? a : -a;
}
const double PI = 3.1415926535898;
const double eps = 1e-10;
const int MAXM = 1e5 + 5;
const int MAXN = 1e5 + 5;
const int INF = 0x3f3f3f3f;
/*头文件模板*/
int n, m;
int d[MAXN];
int par[MAXN];
void init() {
	for(int i = 0; i < MAXN; i ++) {
		par[i] = i;
	}
}
int finds(int x) {
	return par[x] == x ? x : par[x] = finds(par[x]);
}
void unite(int x, int y, int <) {
	x = finds(x);
	y = finds(y);
	if(x != y) {
		par[x] = y, lt --;
	}
}
int main() {
#ifndef ONLINE_JUDGE
	//FIN;
	//FOUT;
#endif
	IO_Init();
	int T, u, v;
	scanf("%d", &T);
	while(T --) {
		mem(d, 0);
		init();
		scanf("%d%d", &n, &m);
		int lt = 0;
		for(int i = 0; i < m; i ++) {
			scanf("%d%d", &u, &v);
			if(!d[v]) lt ++;
			if(!d[u]) lt ++;
			d[v] ++;
			d[u] ++;
			unite(u, v, lt);
		}
		int ans = 0;
		for(int i = 1; i <= n; i ++) {
			if(d[i] & 1) ans ++;
		}
		lt --;
		ans -= (lt + 1) * 2;
		ans /= 2;
		debug(lt);
		if(ans <= 0) {
			printf("%d\n", lt);
		} else {
			printf("%d\n", ans + lt);
		}
	}
	return 0;
}原文:http://blog.csdn.net/qq_18661257/article/details/52254389