Newcoder 38 A.骰⼦的遊戲(水~)
阿新 • • 發佈:2018-11-02
Description
在 和 面前的是兩個骰子,上面分別寫了六個數字。
和 輪流丟擲骰子, 選擇第一個骰子,而 選擇第二個,如果誰投擲出的數更大,誰就可以獲勝。
現在給定這兩個骰子上的 個數字,你需要回答是 獲勝機率更大,還是 獲勝機率更大。(請注意獲勝機率相同的情況)
Input
第一行一個數 ,表示資料個數。
接下來的每一組資料一共有 行,每一行有 個正整數,第一行是第一個骰子上的 個數,第二行是第二個骰子上的 個數。
Output
如果 獲勝機率更大,你需要輸出 ;
如果 獲勝機率更大,你需要輸出 ;
如果獲勝機率一樣大,你需要輸出 。
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
統計 贏 的次數和 贏 的次數比較大小即可,時間複雜度 ,其中
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;
}