SCAU 12新生赛 C ly与lyon的终极巅峰对决
C ly与lyon的终极巅峰对决
Time Limit:1000MS Memory Limit:65535K
题型: 编程题 语言: 无限制
描述
从前有一天,ly与lyon在讨论人工智能里面的博弈问题,恰好,他们提到了五子棋。 当然,这里说的五子棋是指无禁手(不知道什么是禁手的也不用管了,跟这题没关系)的五子棋: 黑先下,黑白轮流下,最先在横竖斜任一方向上形成连续的5个子(或以上)就算赢。 对此,ly和lyon都有自己的一套判断局势的算法,并且根据自己的想法各写了一个判断局况的程序。然而,他们都觉得自己的程序要比对方的优秀,所以, 他们稍作改良,做成了自动决策的对局程序,并拿出来互相pk。目前需要一个自动判断胜负的程序,即最先出现5连子的判胜。
输入格式
第1行输入两个数n和m,用空格分开,n为棋盘横纵坐标的最大值,m为步数: 1<=n<=1000,0<m<=n*n 第2行到第m+1行为第一步到第m步的坐标,每行两个数,用空格分开: x和y,1<=x,y<=n 输入保证不存在重复下子。 (出题人LRC)
输出格式
输出首次分出胜负那一步的序号(第一步为1),如果走完了都没有分出胜负,输出“baga”。
输入样例
5 11 3 3 2 3 2 4 4 3 4 2 3 4 1 5 3 2 5 1 1 1 1 2
输出样例
9
Provider
scau_acm
#include<stdio.h> #include<string.h> int bsitu[1002][1002], wsitu[1002][1002]; int operat(int n, int (*temp)[1002]) { int i, j, start, end, count; for(i=0; i<n; ++i) for(j=0; j<n; ++j) if(temp[i][j] == 1) { if(j+1-5>=0) { for(start=j, count=0; count<5 && temp[i][start]; --start, count++); if(count == 5) return 1; } if(n-j-5>=0) { for(start=j, count=0; count<5 && temp[i][start]; ++start, ++count); if(count == 5) return 1; } if(i+1-5>=0) { for(start=i, count=0; count<5 && temp[start][j]; --start, count++); if(count == 5) return 1; } if(n-i-5>=0) { for(start=i, count=0; count<5 && temp[start][j]; ++start, count++); if(count == 5) return 1; } if(n-j-5>=0 && n-i-5>=0) { for(start=i,end=j,count=0; count<5 && temp[start][end]; ++start, ++end, ++count); if(count == 5) return 1; } if(n-j-5>=0 && i+1-5>=0) { for(start=i, end=j,count=0; count<5 && temp[start][end]; --start, ++end, ++count); if(count == 5) return 1; } if(j+1-5>=0 && n-i-5>=0) { for(start=i, end=j, count=0; count<5 && temp[start][end]; ++start, --end, ++count); if(count == 5) return 1; } if(j+1-5>=0 && i+1-5>=0) { for(start=i, end=j,count=0; count<5 && temp[start][end]; --start, --end, ++count); if(count == 5) return 1; } } return 0; } int main() { int n, m, i, j, flag, x, y; scanf("%d%d", &n, &m); for(i=0; i<n; ++i) { memset(bsitu[i], 0, sizeof(int)*1002); memset(wsitu[i], 0, sizeof(int)*1002); } flag = 0; for(i=1; i<=m; ++i) { scanf("%d%d", &x, &y); if(i%2) {bsitu[x-1][y-1] = 1; if(operat(n, bsitu) && !flag) flag = i;} else {wsitu[x-1][y-1] = 1; if(operat(n, wsitu) && !flag) flag = i;} } if(flag) printf("%d\n", flag); else printf("baga\n"); return 0; }
解题思路:
这样的做法是水了点,不敢保证哪天不删掉

更多内容请关注个人微信公众号 物役记 (微信号:materialchains)
作者:雪影蓝枫
本文版权归作者和博客园共有,欢迎转载,未经作者同意须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?