1. 程式人生 > >Newcoder 38 A.骰⼦的遊戲(水~)

Newcoder 38 A.骰⼦的遊戲(水~)

Description

A l i c e Alice B o

b Bob 面前的是兩個骰子,上面分別寫了六個數字。

A l i c e Alice

B o b Bob 輪流丟擲骰子, A l i c
e Alice
選擇第一個骰子,而 B o b Bob 選擇第二個,如果誰投擲出的數更大,誰就可以獲勝。

​ 現在給定這兩個骰子上的 6 6 個數字,你需要回答是 A l i c e Alice 獲勝機率更大,還是 B o b Bob 獲勝機率更大。(請注意獲勝機率相同的情況)

Input

第一行一個數 T T ,表示資料個數。

接下來的每一組資料一共有 2 2 行,每一行有 6 6 個正整數,第一行是第一個骰子上的 6 6 個數,第二行是第二個骰子上的 6 6 個數。

( 1 T 1 0 5 , n u m 1 0 7 ) (1\le T\le 10^5,num\le 10^7)

Output

如果 A l i c e Alice 獲勝機率更大,你需要輸出 A l i c e Alice

如果 B o b Bob 獲勝機率更大,你需要輸出 B o b Bob

如果獲勝機率一樣大,你需要輸出 T i e Tie

Sample Input

2
3 3 3 3 3 3
1 1 4 4 4 4
1 2 3 4 5 6
6 5 4 3 2 1

Sample Output

Bob
Tie

Solution

統計 A A B B 的次數和 B B A A 的次數比較大小即可,時間複雜度 O ( T n l o g n ) O(Tnlogn) ,其中 n = 6 n=6

Code

#include<cstdio>
#include<algorithm>
using namespace std;
int a[7],b[7];
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		for(int i=0;i<6;i++)scanf("%d",&a[i]);
		for(int i=0;i<6;i++)scanf("%d",&b[i]);
		sort(a,a+6),sort(b,b+6);
		int num1=0,num2=0;
		for(int i=0;i<6;i++)num1+=(lower_bound(b,b+6,a[i])-b);
		for(int i=0;i<6;i++)num2+=(lower_bound(a,a+6,b[i])-a);
		if(num1>num2)printf("Alice\n");
		else if(num1==num2)printf("Tie\n");
		else printf("Bob\n");
	}
	return 0;
}