Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 9 Accepted Submission(s): 4
The playground cannot be transformed in any ways, including reflection and rotation.
Given the number of each type of tiles, you are asked to determine who will win the game if Alice plays first and both players are playing optimal.
For each test case, there are only one line contains 15 integers denoting the number of Tetris tiles of the above 15 types. All the numbers are no greater than 100.
5 4 0 0 0 0 0 0 0 0 0 0 0 0 0
5 5 0 0 0 0 0 0 0 0 0 0 0 0 0
100 100 0 0 0 0 0 0 0 0 0 2 1 0 0
Case #2: Bob
Case #3: Alice
兩個人分別對每種tiles分配一個優先級,
分別計算A選第i中能覆蓋幾次,同時B在A選i後能覆蓋第i種幾次,反之亦是如此。
然後模擬計算兩人覆蓋的次數,比較誰覆蓋次數大。
代碼:
#include<cstdio>
int p1[]={15,5,6,3,4,11,12,13,14,7,8,9,10,1};
int c1[]={2,0,1,1,2,2,1,1,1,1,1,1,1,1,2};
int d2[]={0,2,0,0,0,0,0,0,1,1,0,0,0,0,0};
int p2[]={15,3,4,5,6,11,12,13,14,9,10,7,8,2};
int c2[]={0,2,2,2,1,1,1,1,1,1,1,1,1,1,2};
int d1[]={2,0,0,0,0,0,1,1,0,0,0,0,0,0,0};
int t,tt,a[25];
int main()
{
scanf("%d",&t);
while(t--)
{
int i,j,cur=0,flag=1,b[2][25]={0},s1=0,s2=0;
for(i=1;i<=15;i++)
scanf("%d",&a[i]);
int f1=0,f2=0;
while(1)
{
int f=1;
if(cur==0)
{
for(i=0;i<14;i++)
if(a[p1[i]]>0)
{
f=0;
break;
}
if(f)
f1=1;
if(f1&&f2)
break;
a[p1[i]]--;
s1+=c1[p1[i]-1];
s2+=d2[p1[i]-1];
}
else
{
for(i=0;i<14;i++)
if(a[p2[i]]>0)
{
f=0;
break;
}
if(f)
f2=1;
if(f1&&f2)
break;
a[p2[i]]--;
s2+=c2[p2[i]-1];
s1+=d1[p2[i]-1];
}
cur^=1;
}
printf("Case #%d: %s\n",++tt,s1>s2?"Alice":"Bob");
}
}