Codeforces Beta Round #3
2016-06-05 11:06
337 查看
A - Tic-tac-toe
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice CodeForces
3C
Appoint description:
System Crawler (2016-06-04)
Description
Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3 × 3 grid (one player always draws crosses, the other — noughts).
The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the game is finished. The player who draws crosses goes first. If the grid is filled, but neither Xs, nor 0s form the required line, a draw is
announced.
You are given a 3 × 3 grid, each grid cell is empty, or occupied by a cross or a nought. You have to find the player (first or second), whose turn is next, or print one of the verdicts below:
illegal — if the given board layout can't appear during a valid game;
the first player won — if in the given board layout the first player has just won;
the second player won — if in the given board layout the second player has just won;
draw — if the given board layout has just let to a draw.
Input
The input consists of three lines, each of the lines contains characters ".", "X" or "0" (a period, a capital letter X, or a digit zero).
Output
Print one of the six verdicts: first, second, illegal, the first player won, the
second player won or draw.
Sample Input
Input
Output
暴力求解:
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice CodeForces
3C
Appoint description:
System Crawler (2016-06-04)
Description
Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3 × 3 grid (one player always draws crosses, the other — noughts).
The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the game is finished. The player who draws crosses goes first. If the grid is filled, but neither Xs, nor 0s form the required line, a draw is
announced.
You are given a 3 × 3 grid, each grid cell is empty, or occupied by a cross or a nought. You have to find the player (first or second), whose turn is next, or print one of the verdicts below:
illegal — if the given board layout can't appear during a valid game;
the first player won — if in the given board layout the first player has just won;
the second player won — if in the given board layout the second player has just won;
draw — if the given board layout has just let to a draw.
Input
The input consists of three lines, each of the lines contains characters ".", "X" or "0" (a period, a capital letter X, or a digit zero).
Output
Print one of the six verdicts: first, second, illegal, the first player won, the
second player won or draw.
Sample Input
Input
X0X .0. .X.
Output
second
暴力求解:
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> using namespace std; char a[5][5]; int numx,numo; bool row(char aim){ for(int i=0;i<3;i++){ int j; for(j=0;j<3;j++) if(a[i][j]!=aim) break; if(j==3) return 1; } return 0; } bool col(char aim){ for(int j=0;j<3;j++){ int i; for(i=0;i<3;i++) if(a[i][j]!=aim) break; if(i==3) return 1; } return 0; } bool xie(char aim){ if((a[1][1]==aim&&a[0][0]==a[1][1]&&a[1][1]==a[2][2])||(a[1][1]==aim&&a[0][2]==a[1][1]&&a[2][0]==a[1][1])) return 1; else return 0; } void judge(){ if((numx-numo)==0||(numx-numo)==1){ int ans1=0; ans1=col('X'); ans1+=row('X'); ans1+=xie('X'); int ans2=0; ans2=col('0'); ans2+=row('0'); ans2+=xie('0'); if(ans1&&!ans2){ if(numx-numo==1) cout<<"the first player won"<<endl; else cout<<"illegal"<<endl; return ; }else if(!ans1&&ans2){ if(numx==numo) cout<<"the second player won"<<endl; else cout<<"illegal"<<endl; return ; }else if(ans1&&ans2){ cout<<"illegal"<<endl; }else if(numx+numo==9){ cout<<"draw"<<endl; }else{ if(abs(numx-numo)==1) cout<<"second"<<endl; else if(numx==numo) cout<<"first"<<endl; } } else cout<<"illegal"<<endl; } int main() { numx=0;numo=0; for(int i=0;i<3;i++) { gets(a[i]); for(int j=0;j<3;j++) if(a[i][j]=='X') numx++; else if(a[i][j]=='0') numo++; } judge(); }
相关文章推荐
- C++第7次实验
- 机器视觉开源代码集合-1
- Gensee移动SDK之(一)结构组成
- 11.1节练习
- MAC MySQL 重置密码
- 个人最终总结
- mac 苹果鼠标 magic mouse2 当触摸代替点击当触摸板教程
- 源码推荐(0601):可高度自定义的TabBarController,微信页面
- 非系统消息的使用方法及SendMessage()和PostMessage()的区别
- 常用到的Tomcat的修改方法
- (loadrunner 四)创建场景
- nginx+tomcat负载均衡+动静分离+redis集中管理session
- 位操心常见经典用法
- 2016 CocosPods安装教程
- Team Foundation Server 安装配置教程
- Unity两点间的线性插值及其协程的使用
- A dynamic niching clustering algorithm based on individual-connectedness and its application to colo
- Msql编辑数据表的默认存储引擎
- Team Foundation Server 安装配置教程
- 冲刺第二阶段工作总结09