Codeforces 3C

题意

给你一个井字棋的棋谱,判断井字棋的状态

first, 第一个人走

second 第二个人走

illegal 不合法

the first player won 第一个人赢

the second player won 第二个人赢

draw 平局

思路

暴力枚举每种赢的状态

答案中没有这种样例 (思考一下)

X0X
00X
0XX

代码

/* **********************************************
Auther: ???D?òacm?ü?ü
Created Time: 2015-7-29 15:37:22
File Name   : 3c.cpp
*********************************************** */
#include <iostream>
#include <fstream>
#include <cstring>
#include <climits>
#include <deque>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <ctime>
#include <bitset>
#include <functional>
#include <algorithm>
using namespace std;
#define lson L,m,rt<<1
#define rson m+1,R,rt<<1|1
#define ll long long
#define N 11111

char mp[4][4];
int flag1 ;
int flag2 ;
void judge1(){
        if(mp[0][0]==‘X‘&&mp[0][1]==‘X‘&&mp[0][2]==‘X‘) flag1 = 1;
        if(mp[1][0]==‘X‘&&mp[1][1]==‘X‘&&mp[1][2]==‘X‘) flag1 = 1;
        if(mp[2][0]==‘X‘&&mp[2][1]==‘X‘&&mp[2][2]==‘X‘) flag1 = 1;
        if(mp[0][0]==‘X‘&&mp[1][0]==‘X‘&&mp[2][0]==‘X‘) flag1 = 1;
        if(mp[0][1]==‘X‘&&mp[1][1]==‘X‘&&mp[2][1]==‘X‘) flag1 = 1;
        if(mp[0][2]==‘X‘&&mp[1][2]==‘X‘&&mp[2][2]==‘X‘) flag1 = 1;
        if(mp[0][0]==‘X‘&&mp[1][1]==‘X‘&&mp[2][2]==‘X‘) flag1 = 1;
        if(mp[0][2]==‘X‘&&mp[1][1]==‘X‘&&mp[2][0]==‘X‘) flag1 = 1;
}
void judge2(){
        if(mp[0][0]==‘0‘&&mp[0][1]==‘0‘&&mp[0][2]==‘0‘) flag2 = 1;
        if(mp[1][0]==‘0‘&&mp[1][1]==‘0‘&&mp[1][2]==‘0‘) flag2 = 1;
        if(mp[2][0]==‘0‘&&mp[2][1]==‘0‘&&mp[2][2]==‘0‘) flag2 = 1;
        if(mp[0][0]==‘0‘&&mp[1][0]==‘0‘&&mp[2][0]==‘0‘) flag2 = 1;
        if(mp[0][1]==‘0‘&&mp[1][1]==‘0‘&&mp[2][1]==‘0‘) flag2 = 1;
        if(mp[0][2]==‘0‘&&mp[1][2]==‘0‘&&mp[2][2]==‘0‘) flag2 = 1;
        if(mp[0][0]==‘0‘&&mp[1][1]==‘0‘&&mp[2][2]==‘0‘) flag2 = 1;
        if(mp[0][2]==‘0‘&&mp[1][1]==‘0‘&&mp[2][0]==‘0‘) flag2 = 1;
}
int main(){
    for(int i=0;i<3;i++){
        scanf("%s",mp[i]);
    }
    int cnt1=0,cnt2=0;
    flag1 = 0;
    flag2 = 0;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            if(mp[i][j]==‘X‘) cnt1++;
            if(mp[i][j]==‘0‘) cnt2++;
        }
    }
   // printf("%d %d %d\n",cnt1,cnt2,abs(cnt1-cnt2));
    judge1();
    judge2();
    if(cnt1-cnt2>1||cnt2>cnt1){
       puts("illegal");
       return 0;
    }

    if(cnt1+cnt2!=9&&abs(cnt1-cnt2)<=1){
        if(flag1&&flag2) puts("illegal");
        else if(flag1&&cnt1>cnt2) puts("the first player won");
        else if(flag2&&cnt2==cnt1) puts("the second player won");
        else if(flag2&&cnt1>cnt2||(flag1&&cnt1==cnt2)) puts("illegal");
        else{
        if(cnt1>cnt2) puts("second");
        else puts("first");
        }
    }

    if(cnt1+cnt2==9){
    if(flag1&&flag2) puts("illegal");
    if(!flag1&&!flag2) puts("draw");
    if(flag1) puts("the first player won");
    if(flag2) puts("illegal");
    }
}

版权声明:都是兄弟,请随意转载,请注明兄弟是谁

时间: 2024-09-17 19:25:48

Codeforces 3C的相关文章

Codeforces Round #258 (Div. 2)

A - Game With Sticks 题目的意思: n个水平条,m个竖直条,组成网格,每次删除交点所在的行和列,两个人轮流删除,直到最后没有交点为止,最后不能再删除的人将输掉 解题思路: 每次删除交点所在的行和列,则剩下n-1行和m-1列,直到行或列被删完为止,最多删除的次数为min(n,m),删除min(n,m)后剩余的都是行或者列(注意行与行,列与列之间不可能有交点).只需要判断min(n,m)的奇偶性. #include <iostream> #include <vector&

Educational Codeforces Round 56 (Rated for Div. 2) ABCD

题目链接:https://codeforces.com/contest/1093 A. Dice Rolling 题意: 有一个号数为2-7的骰子,现在有一个人他想扔到几就能扔到几,现在问需要扔多少次,能使扔出的总和等于xi. 题解: 由于是special judge,模拟一下搞搞就行了= = 代码如下: #include <bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; int n; while(t--

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b

Codeforces 841D Leha and another game about graph - 差分

Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or  - 1. To pass th

Codeforces Round #286 (Div. 1) A. Mr. Kitayuta, the Treasure Hunter DP

链接: http://codeforces.com/problemset/problem/506/A 题意: 给出30000个岛,有n个宝石分布在上面,第一步到d位置,每次走的距离与上一步的差距不大于1,问走完一路最多捡到多少块宝石. 题解: 容易想到DP,dp[i][j]表示到达 i 处,现在步长为 j 时最多收集到的财富,转移也不难,cnt[i]表示 i 处的财富. dp[i+step-1] = max(dp[i+step-1],dp[i][j]+cnt[i+step+1]) dp[i+st

Codeforces 772A Voltage Keepsake - 二分答案

You have n devices that you want to use simultaneously. The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power store

Educational Codeforces Round 21 G. Anthem of Berland(dp+kmp)

题目链接:Educational Codeforces Round 21 G. Anthem of Berland 题意: 给你两个字符串,第一个字符串包含问号,问号可以变成任意字符串. 问你第一个字符串最多包含多少个第二个字符串. 题解: 考虑dp[i][j],表示当前考虑到第一个串的第i位,已经匹配到第二个字符串的第j位. 这样的话复杂度为26*n*m*O(fail). fail可以用kmp进行预处理,将26个字母全部处理出来,这样复杂度就变成了26*n*m. 状态转移看代码(就是一个kmp

Codeforces Round #408 (Div. 2) B

Description Zane the wizard is going to perform a magic show shuffling the cups. There are n cups, numbered from 1 to n, placed along the x-axis on a table that has m holes on it. More precisely, cup i is on the table at the position x?=?i. The probl