A Yellowstar的第一道题 博弈

5 篇文章 0 订阅

题目链接:点击打开链接

先来个暴力程序找下规律。

若n*r*c 是偶数,则是必败态,输出0.000000

否则对于3*3*3 赢的位置有:

1 0 1
0 1 0
1 0 1
0 1 0
1 0 1
0 1 0
1 0 1
0 1 0
1 0 1

1为必胜点。也就是说左上角是1,这样扩散出去。

答案就是所有1位置的概率和。

暴力程序:

#include <cstdio>
#include <cstring>

int n, m, d, step[6][3] = {0,0,1, 0,0,-1, 0,1,0, 0,-1,0, 1,0,0, -1,0,0};
bool inmap(int x, int y,int z){return 1<=x&&x<=n&&1<=y&&y<=m&&1<=z&&z<=d;}
bool vis[20][20][20];
bool dfs(int x, int y,int z){//0是先手
    vis[x][y][z] = 1;
    for(int i = 0; i < 6; i++)
    {
        int a = x + step[i][0], b = y + step[i][1], c = z + step[i][2];
        if(!inmap(a,b,c) || vis[a][b][c])continue;
        if(dfs(a,b,c))
        {
            vis[x][y][z] = 0;
            return false;
        }
    }
    vis[x][y][z] = 0;
    return true;
}
bool work(){
    memset(vis, 0, sizeof vis);
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++){
        for(int k = 1; k <= d; k++)
            printf("%d ", dfs(i,j,k));
            puts("");
        }
}
int main(){
    while(~scanf("%d%d%d", &n, &m, &d))
        work();
    return 0;
}
ac代码:

#include <cstdio>
int main() {
	int n, r, c;
	while(~scanf("%d%d%d", &n, &r, &c)) {
		double x, sum = 0;
		for(int i = 1; i <= n; i ++) {
			for(int j = 1; j <= r; j ++) {
				for(int k = 1; k <= c; k ++) {
					scanf("%lf", &x);
					if((i + j + k) & 1) sum += x;
				}
			}
		}
		if((n*r*c) & 1) printf("%.6f\n", sum);
		else puts("0.000000");
	}
	return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值