week6限时模拟-掌握魔法の东东 II
思路:
- 考虑使用结构体表示牌,使用数组表示所有牌,之后问题转化为从
A*B
张牌中选出三张牌,并且三张牌不是初始的两张牌,对于5张牌进行判断类型即可。选出三张牌直接循环枚举即可。 - 注意:主要是牌的类型判断出现过逻辑上的错误。在判断之前先排序便于后序操作。
实现:
#include<iostream>
#include<algorithm>
using namespace std;
struct card
{
int a,b;
card(){};
card(int a1,int b1)
{
a=a1;
b=b1;
};
void operator=(card x)
{
a=x.a;
b=x.b;
};
};
card x[110];
int A,B,a1,b1,a2,b2,n;
int shunzi[5];
int ans[10]={0};
bool vis[110][110][110]={0};
int check(int c1,int c2,int c3)
{
bool flag2=0,flag3=0;
{
shunzi[0]=x[c1].a;
shunzi[1]=x[c2].a;
shunzi[2]=x[c3].a;
shunzi[3]=a1;
shunzi[4]=a2;
}
sort(shunzi,shunzi+5);
flag2=1;
for(int i=0;i<4;++i)
{
if(shunzi[i]+1!=shunzi[i+1])
{
flag2=false;
break;
}
}
if(b1==b2)
{
if(x[c1].b==x[c2].b && x[c3].b==x[c2].b && b1==x[c1].b)
flag3=true;
}
if(flag2 && flag3)
return 1;
else if(flag2)
return 2;
else if(flag3)
return 3;
int count=0;
if(shunzi[0]==shunzi[3] || shunzi[1]==shunzi[4])
return 4;
if((shunzi[0]==shunzi[2]&&shunzi[3]==shunzi[4])
|| (shunzi[0]==shunzi[1] && shunzi[2]==shunzi[4]))
return 5;
if((shunzi[1]==shunzi[2] && shunzi[3]==shunzi[4])
|| (shunzi[0]==shunzi[1] && shunzi[3]==shunzi[4])
||(shunzi[0]==shunzi[1] && shunzi[2]==shunzi[3]))
return 6;
if(shunzi[0]==shunzi[2] || shunzi[1]==shunzi[3] || shunzi[2]==shunzi[4])
return 7;
for(int i=0;i<4;++i)
{
if(shunzi[i]==shunzi[i+1])
return 8;
}
return 9;
}
bool check2(int i,int j,int k)
{
if((x[i].a==a1 &&x[i].b==b1) || (x[j].a==a1&&x[j].b==b1)
|| (x[k].a==a1 &&x[k].b==b1) || (x[j].a==a2&&x[j].b==b2)
|| (x[i].a==a2&&x[i].b==b2) || (x[k].a==a2&&x[k].b==b2))
return false;
return true;
}
int main()
{
scanf("%d %d",&A,&B);
scanf("%d %d %d %d",&a1,&b1,&a2,&b2);
for(int i=0;i<A;++i)
{
for(int j=0;j<B;++j)
{
int cur=i*B+j;
x[cur].a=i;
x[cur].b=j;
}
}
n=A*B;
int f;
for(int i=0;i<n-2;++i)
{
for(int j=i+1;j<n-1;++j)
{
for(int k=j+1;k<n;++k)
{
if(check2(i,j,k))
{
f=check(i,j,k);
ans[f]++;
}
}
}
}
for(int i=1;i<10;++i)
cout<<ans[i]<<" ";
return 0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)