Codeforces Round #390 (Div. 2)-B Ilya and tic-tac-toe game(模拟)
来源:互联网 发布:网络探案小说排行榜 编辑:程序博客网 时间:2024/05/22 06:07
记录一个菜逼的成长。。
题目链接
题目大意:
有一个4*4的图,先手画’x’,后手画’o’,谁先满足在对角线或者横线或竖线上有三个连续的标记,则这个人获胜。
问在这个图上画一个’x’标记,是否可以获胜。
直接暴力模拟这个过程即可。对角线两条,横线一条,竖线一条
#include <bits/stdc++.h>using namespace std;#define cl(a,b) memset(a,b,sizeof(a))#define pb push_back#define mp make_pair#define lowbit(x) (x)&(-x)typedef long long LL;typedef pair<int,int> PII;const int INF = 0x3f3f3f3f;const int maxn = 100 + 10;char g[5][5];char s[] = {'x','o'};bool check(int x,int y,int a){ int cnt = 1; for( int i = y - 1; i > 0 && g[x][i] == s[a]; i-- )cnt++; for( int i = y + 1; i <= 4 && g[x][i] == s[a]; i++ )cnt++; if(cnt >= 3)return true; cnt = 1; for( int i = x-1; i > 0 && g[i][y] == s[a]; i-- )cnt++; for( int i = x+1; i <= 4 && g[i][y] == s[a]; i++ )cnt++; if(cnt >= 3)return true; cnt = 1; for( int i = 1; x-i > 0 && y-i > 0 && g[x-i][y-i] == s[a]; i++ )cnt++; for( int i = 1; x+i <= 4 && y+i <= 4 && g[x+i][y+i] == s[a]; i++ )cnt++; if(cnt >= 3)return true; cnt = 1; for( int i = 1; x-i > 0 && y+i <= 4 && g[x-i][y+i] == s[a]; i++ )cnt++; for( int i = 1; x+i <= 4 && y-i > 0 && g[x+i][y-i] == s[a]; i++)cnt++; if(cnt >= 3)return true; return false;}int main(){ for( int i = 1; i <= 4; i++ ){ scanf("%s",g[i]+1); } int flag = 0; for( int i = 1; i <= 4; i++ ){ for( int j = 1; j <= 4; j++ ){ if(g[i][j] == '.' && check(i,j,0)){ flag = 1; break; } } if(flag)break; } if(flag)puts("YES"); else puts("NO"); return 0;}
0 0
- Codeforces Round #390(Div. 2)B. Ilya and tic-tac-toe game【模拟】
- Codeforces Round #390 (Div. 2)-B Ilya and tic-tac-toe game(模拟)
- Codeforces Round #390 (Div. 2) B. Ilya and tic-tac-toe game(dfs)
- Codeforces Round #390 (Div. 2)B Ilya and tic-tac-toe game
- Codeforces #390 (Div. 2) B. Ilya and tic-tac-toe game ( DFS
- 【Codeforces 754 B Ilya and tic-tac-toe game】
- 【codeforces 754B】 Ilya and tic-tac-toe game
- codeforces 754 B Ilya and tic-tac-toe game
- CodeForces 754B Ilya and tic-tac-toe game
- B. Ilya and tic-tac-toe game
- Codeforces-754B-Ilya and tic-tac-toe game(简单模拟判断)
- Cdoeforces 754 B - Ilya and tic-tac-toe game
- 754B Ilya and tic-tac-toe game
- 754B. Ilya and tic-tac-toe game
- 2017寒假集训-小题训练1:F - Ilya and tic-tac-toe game
- Codeforces Beta Round #3 / 3C Tic-tac-toe (超级模拟)
- 001 tic-tac-toe game
- C. Tic-tac-toe【模拟】
- 1.安卓基础——哪里不懂写哪里,没有顺序没有规则,哈哈……
- struts2的contextmap和valueStack
- Mac Xcode崩溃 (打开ios项目引起崩溃)
- 用keil创建汇编工程时,选择出来器之后,不要加载启动项
- Fragment详解之五——Fragment间参数传递
- Codeforces Round #390 (Div. 2)-B Ilya and tic-tac-toe game(模拟)
- Charles抓取iPhone的HTTPS请求
- 让你明白response.sendRedirect()与request.getRequestDispatcher().forward()区别
- RecyclerView 必知必会
- 浅拷贝问题解决,编写拷贝构造函数,深拷贝
- Fragment跳转时传递参数及结果回传的方法
- redis中缓存的数据与数据库数据一致性的方案
- 快速找到未知长度单链表的中间节点
- linux驱动:设备-总线-驱动(以TI+DM8127中GPIO为例)