Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!]

A. Game

题解:排序后取中间的数。

B. Minesweeper

题解:检查每一位是否合法就行。

感受:永远都被B题坑.。。。。。if there is a digit kk in the cell, then exactly kk neighboring cells have bombs. 周围只是没炸弹而已,而不是全部'.'。WA了四次,强行掉分,囧rz。

#pragma warning(disable:4996)
#include<cmath>
#include<string>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define mem(arr,in) memset(arr,in,sizeof(arr))
using namespace std;

const int maxn = 1005;

int n, m;
char mp[200][200];

int dx[] = { -1,-1,0,1,1,1,0,-1 };
int dy[] = { 0,1,1,1,0,-1,-1,-1 };

bool check1(int a, int b) {
    for (int i = 0; i <= 7; i++) {
        int mx = dx[i] + a;
        int my = dy[i] + b;
        if (mx >= 0 && mx < n && my >= 0 && my < m && mp[mx][my] == '*') return false;
    }
    return true;
}

bool check2(int a, int b) {
    int cnt = 0;
    for (int i = 0; i <= 7; i++) {
        int mx = dx[i] + a;
        int my = dy[i] + b;
        if (mx >= 0 && mx < n && my >= 0 && my < m && mp[mx][my] == '*') cnt++;
    }
    int k = mp[a][b] - '0';
    if (cnt == k) return true;
    else return false;
}

bool Solve() {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (mp[i][j] == '.') {
                if (!check1(i, j)) return false;
            }
            else if (mp[i][j] >= '1' && mp[i][j] <= '8') {
                if (!check2(i, j)) return false;
            }
        }
    }
    return true;
}

int main()
{
    while (cin >> n >> m) {
        for (int i = 0; i < n; i++) scanf("%s", mp[i]);
        //for (int i = 0; i < n; i++) printf("%s\n", mp[i]);
        if (Solve()) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C. Finite or not?

题解:while(((p*b)%q)) p=p*b%q;这样貌似会超时,比赛的时候不敢写。

猜你喜欢

转载自www.cnblogs.com/zgglj-com/p/9044203.html