1. 程式人生 > >CF-Codeforces Round #483 (Div. 2) A~D

CF-Codeforces Round #483 (Div. 2) A~D

ACM模版

A-Game

描述

描述

題解

兩個人依次取數,A 每次取大的,B 每次取小的,直到剩餘一個數,輸出這一個,排序即可。

程式碼

#include <iostream>
#include <algorithm>

using namespace std;

const int MAXN = 1111;

int n;
int a[MAXN];

int main(int argc, const char * argv[])
{
    while (cin >> n)
    {
        for (int i = 0
; i < n; i++) { cin >> a[i]; } sort(a, a + n); cout << a[n - n / 2 - 1] << '\n'; } return 0; }

B-Minesweeper

描述

這裡寫圖片描述

題解

掃雷遊戲,注意空地情況可以理解為 0

程式碼

#include <iostream>
#include <cstring>

using namespace std
; const int MAXN = 111; const int DIR[][2] = { {-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1} }; struct cell { int dig; int cnt; int flag; } C[MAXN][MAXN]; int n, m; bool judge(int x, int y) { if (x >= 0 && y >= 0 && x < n && y < m) { return
1; } return 0; } void change(int x, int y) { C[x][y].flag = 1; int x_, y_; for (int i = 0; i < 8; i++) { x_ = x + DIR[i][0]; y_ = y + DIR[i][1]; if (judge(x_, y_)) { C[x_][y_].cnt++; } } } int main(int argc, const char * argv[]) { while (cin >> n >> m) { getchar(); memset(C, 0, sizeof(C)); char x; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { x = getchar(); if (x == '.') { x = '0'; } if (x >= '0' && x < '9') { C[i][j].dig = x - '0'; } if (x == '*') { change(i, j); } } getchar(); } int tag = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (!C[i][j].flag && C[i][j].dig != C[i][j].cnt) { cout << "NO\n"; tag = 0; break; } } if (!tag) { break; } } if (tag) { cout << "YES\n"; } } return 0; }

C-Finite or not?

數論。詳解>>>

D-XOR-pyramid

DP 或 O(n2) 暴力預處理後 O(1) 查詢。詳解>>>