SDU程序设计与实践模拟Week6
A- 掌握魔法の东东 II
Input&&Output:
sample:
#Input
5 2
1 0 3 1
#Output
0 0 0 0 8 0 12 36 0
#Input
25 4
0 0 24 3
#Output
0 2 18 0 0 644 1656 36432 113344
题解
1.本题粗略以看是一道组合数学的问题,然鹅这么做不是不可以但是太烦了(本人尝
试了最终头秃放弃 哭.jpg)
2.我们细心观察可以发现本题实际上直接枚举就可以做,毕竟只有上限100个数,从
中取三个不重复的数,三重循环也不会超时。
3.取出数以后就是判断阶段,先说一下我的思路(low爆了):
首先我发现很多判断的结果都是由关联的,因此先排序
然后炸弹我们发现是按照数字大小排序后 前四个或后四个数相同 实际上就是0~3或1~4(两对或一对或三条也可以这么判断)
同花其实是花色排序
顺子实际上就是判断后一项是否比前一项大一
剩余的就是杂牌
PS:后读过某大佬的代码,发现自己写的代码low爆了,做一个简述,实际上不需要
建立struct直接写映射就好,其次我循环处的取数也写的很冗余,实际上内层直接取
就可以了,外部的暂时保存属实所欲,最后就是关于结果的判断,其实大佬的判断的
思想也差不多,但是他的代码很简洁,比如我们可以直接存储数组中相同数的个数然
后从个数先进行判断,顺子的判断实际上差不多但是可以不建中间数组直接循环使用
bool值判断。
C++代码
#include<iostream>
#include<algorithm>
using namespace std;
struct c{
int num,col;
bool operator<(c &x){
if(num!=x.num) return num<x.num;
return col<x.col;
}
bool operator==(c &x){
return num == x.num;
}
};
int A,B,x,y;
int pos=0;
c curr;
c poke[5];
c poke2[5];
int ans[9];
void init(){
for(int i = 0;i<9;i++) ans[i] = 0;
}
void get(int i){
x = i/B;
y = i%B;
curr.num = x;
curr.col = y;
}
int aa = 0;
bool same(c c1,c c2){
return c1.col==c2.col&&c1.num==c2.num;
}
void judge(){
sort(poke2,poke2+5);
int mid[4],mid2[4];
for(int i = 0;i<4;i++){
mid[i] = poke2[i+1].num-poke2[i].num;
mid2[i] = abs(poke2[i+1].col-poke2[i].col);
}
if(poke2[0]==poke2[3]||poke2[1]==poke2[4]) ans[1]++;//{ans[1]++;cout<<"//炸弹 "<<endl;}
else if((poke2[1] == poke2[3])||(poke2[0] == poke2[2] && poke2[3].num != poke2[4].num)||(poke2[2] == poke2[4] && poke2[0].num != poke2[1].num)) ans[5]++;//{ans[5]++;cout<<"//三条"<<endl;}
else if((poke2[0] == poke2[2] && poke2[3] == poke2[4])||(poke2[2] == poke2[4] && poke2[0] == poke2[1])) ans[2]++;//{ans[2]++;cout<<"//三代二"<<endl;}
else if(((poke2[0] == poke2[1]) && (poke2[2] == poke2[3]))||((poke2[2] == poke2[1]) && (poke2[4] == poke2[3]))||((poke2[0] == poke2[1]) && (poke2[4] == poke2[3]))) ans[6]++;//{ans[6]++;cout<<"//两对"<<endl;}
else if((poke2[0]==poke2[1])||(poke2[1]==poke2[2])||(poke2[2]==poke2[3])||(poke2[3]==poke2[4])) ans[7]++;//{ans[7]++;cout<<"//一对 "<<endl;}
else if((mid[0]*mid[1]*mid[2]*mid[3] == 1)&&(mid2[0]+mid2[1]+mid2[2]+mid2[3] == 0)) ans[0]++;//{ans[0]++;cout<<"//同花顺 "<<endl;}
else if(mid[0]*mid[1]*mid[2]*mid[3] == 1) ans[4]++;//{ans[4]++;cout<<"//顺子"<<endl;}
else if(mid2[0]+mid2[1]+mid2[2]+mid2[3] == 0) ans[3]++;//{ans[3]++;cout<<"//同花"<<endl;}
else ans[8]++;//{ans[8]++; cout<<"啥都不是"<<endl;}
}
void solve(){
for(int i = 0;i<A*B;i++){
for(int ki=0;ki<2;ki++) poke2[ki] = poke[ki];
get(i);
if(same(curr,poke[0])||same(curr,poke[1])) continue;
poke2[pos++] = curr;
poke[pos-1] = curr;
for(int j=i+1;j<A*B;j++){
for(int ki=0;ki<3;ki++) poke2[ki] = poke[ki];
get(j);
if(same(curr,poke[0])||same(curr,poke[1])) continue;
poke2[pos++] = curr;
poke[pos-1] = curr;
for(int k=j+1;k<A*B;k++){
get(k);
for(int ki=0;ki<4;ki++) poke2[ki] = poke[ki];
if(same(curr,poke[0])||same(curr,poke[1])) continue;
//cout<<i<<" "<<j<<" "<<k<<" \n";
poke2[pos++] = curr;
judge();
aa++;
pos--;
}
pos--;
}
pos--;
}
}
int main(){
cin>>A>>B;
init();
int a1,b1;
cin>>a1>>b1;
curr.num = a1;
curr.col = b1;
poke[pos++] = curr;
cin>>a1>>b1;
curr.num = a1;
curr.col = b1;
poke[pos++] = curr;
solve();
for(int i = 0;i<9;i++)
cout<<ans[i]<<" ";
cout<<endl;
return 0;
}