P2670 [NOIP2015 普及组] 扫雷游戏
#include <cstdio>
char mine[105][105];
int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
int main()
{
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%s", mine[i]);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (mine[i][j] == '*') continue; // 跳过这一次循环
int cnt = 0;
for (int k = 0; k < 8; k++) {
int x = i + dx[k], y = j + dy[k];
if (x >= 0 && x < n && y >= 0 && y < m && mine[x][y] == '*')
cnt++;
}
mine[i][j] = '0' + cnt;
}
}
for (int i = 0; i < n; i++) printf("%s\n", mine[i]);
return 0;
}
P1042 [NOIP2003 普及组] 乒乓球
#include <cstdio>
#include <string>
using namespace std;
int score[2] = {11, 21};
int main() {
char ch = getchar();
string record;
while (ch != 'E') {
if (ch == 'W' || ch == 'L') record += ch;
ch = getchar();
}
int len = record.length();
for (int i = 0; i < 2; i++) {
int x = 0, y = 0;
for (int j = 0; j < len; j++) {
if (record[j] == 'W') x++;
else y++;
if (max(x, y) >= score[i] && abs(x - y) >= 2) {
printf("%d:%d\n", x, y);
x = y = 0;
}
}
printf("%d:%d\n", x, y);
if (i == 0) printf("\n");
}
return 0;
}
P1563 [NOIP2016 提高组] 玩具谜题
#include <cstdio>
struct Toy {
int d;
char name[15];
};
Toy t[100005];
int main()
{
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d%s", &t[i].d, t[i].name);
}
int cur = 0;
for (int i = 0; i < m; i++) {
int a, s;
scanf("%d%d", &a, &s);
int flag = -1;
if (a + t[cur].d == 1) flag = 1;
cur = (cur + n + flag * s) % n;
}
printf("%s\n", t[cur].name);
return 0;
}
P4924 [1007] 魔法少女小Scarlet
#include <cstdio>
using namespace std;
int a[505][505], tmp[505][505];
int n;
void print() {
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j)
printf("%d ", a[i][j]);
printf("\n");
}
}
void rotate(int x, int y, int len, int d) {
for (int i = 0; i < len; ++i)
for (int j = 0; j < len; ++j)
if (d == 1) tmp[x + i][y + j] = a[x + j][y + len - i - 1];
else tmp[x + i][y + j] = a[x + len - j - 1][y + i];
for (int i = 0; i < len; ++i)
for (int j = 0; j < len; ++j)
a[x + i][y + j] = tmp[x + i][y + j];
}
int main()
{
int m;
scanf("%d%d", &n, &m);
int cnt = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
a[i][j] = ++cnt;
for (int i = 0; i < m; i++) {
int x, y, r, z;
scanf("%d%d%d%d", &x, &y, &r, &z);
rotate(x - r, y - r, 2 * r + 1, z);
}
print();
return 0;
}
P1328 [NOIP2014 提高组] 生活大爆炸版石头剪刀布
#include <cstdio>
int res[5][5] = {
{0, -1, 1, 1, -1},
{1, 0, -1, 1, -1},
{-1, 1, 0, -1, 1},
{-1, -1, 1, 0, 1},
{1, 1, -1, -1, 0}};
int a[205], b[205];
int main()
{
int n, na, nb;
scanf("%d%d%d", &n, &na, &nb);
for (int i = 0; i < na; ++i) scanf("%d", &a[i]);
for (int i = 0; i < nb; ++i) scanf("%d", &b[i]);
int sa = 0, sb = 0;
for (int i = 0; i < n; ++i) {
int r = res[a[i % na]][b[i % nb]];
if (r == 1) ++sa;
else if (r == -1) ++sb;
}
printf("%d %d\n", sa, sb);
return 0;
}
P1067 [NOIP2009 普及组] 多项式输出
#include <cstdio>
#include <cmath>
using namespace std;
int a[105];
int main()
{
int n;
scanf("%d", &n);
for (int i = 0; i <= n; ++i) scanf("%d", &a[i]);
int bg = 0;
while (bg <= n && a[bg] == 0) ++bg;
if (bg == n + 1) printf("0");
for (int i = bg; i <= n; ++i) {
if (a[i] == 0) continue;
if (i != bg) {
if (a[i] > 0) printf("+");
else printf("-");
} else if (a[i] < 0) printf("-");
if (abs(a[i]) != 1 || i == n) printf("%d", abs(a[i]));
if (i < n) {
if (i == n - 1) printf("x");
else printf("x^%d", n - i);
}
}
return 0;
}
P1098 [NOIP2007 提高组] 字符串的展开
#include <iostream>
#include <string>
using namespace std;
string ans, s;
int p1, p2, p3;
bool is_lower(char ch) {
return ch >= 'a' && ch <= 'z';
}
bool is_digit(char ch) {
return ch >= '0' && ch <= '9';
}
bool can_expand(char l, char r) {
if (is_lower(l) && is_lower(r) && l < r) return true;
if (is_digit(l) && is_digit(r) && l < r) return true;
return false;
}
string expand(int l, int r) {
string ret;
if (p1 == 3) {
for (char ch = s[l] + 1; ch < s[r]; ++ch)
for (int i = 0; i < p2; ++i) ret += '*';
} else if (is_digit(s[l]) || p1 == 1) {
if (p3 == 2) {
for (char ch = s[r] - 1; ch > s[l]; --ch)
for (int i = 0; i < p2; ++i) ret += ch;
} else {
for (char ch = s[l] + 1; ch < s[r]; ++ch)
for (int i = 0; i < p2; ++i) ret += ch;
}
} else if (p1 == 2) {
if (p3 == 2) {
for (char ch = s[r] - 1; ch > s[l]; --ch)
for (int i = 0; i < p2; ++i) ret += char(ch - 32);
} else {
for (char ch = s[l] + 1; ch < s[r]; ++ch)
for (int i = 0; i < p2; ++i) ret += char(ch - 32);
}
}
return ret;
}
int main()
{
cin >> p1 >> p2 >> p3 >> s;
int bg = 0;
int len = s.length();
int cur = -1;
while (bg < len && cur < len) {
cur = s.find('-', cur + 1);
if (cur == -1) {
ans += s.substr(bg);
break;
}
if (cur != 0 && cur + 1 != s.size()) {
if (can_expand(s[cur - 1], s[cur + 1])) {
ans += s.substr(bg, cur - bg);
ans += expand(cur - 1, cur + 1);
ans += s[cur + 1];
bg = cur + 2;
++cur;
}
}
}
cout << ans << endl;
return 0;
}
P1518 [USACO2.4] 两只塔姆沃斯牛 The Tamworth Two
#include <cstdio>
char s[15][15];
// 0 1 2 3
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
bool vis[15][15][4][15][15][4];
bool valid(int x) {
return x>=0 && x<=9;
}
void one_minute(int &x, int &y, int &d) {
int new_x = x + dx[d], new_y = y + dy[d];
if (valid(new_x) && valid(new_y) && s[new_x][new_y]!='*') {
x = new_x; y = new_y;
} else {
d = (d + 1) % 4;
}
}
int main()
{
int fx, fy, fd, cx, cy, cd;
for (int i = 0; i < 10; i++) scanf("%s", s[i]);
for (int i = 0; i < 10; i++)
for (int j = 0; j < 10; j++) {
if (s[i][j] == 'C') {
cx = i; cy = j;
}
if (s[i][j] == 'F') {
fx = i; fy = j;
}
}
fd = cd = 0;
int ans = 0;
vis[fx][fy][fd][cx][cy][cd]=true;
while (fx!=cx || fy!=cy) { // !(fx==cx && fy==cy)
one_minute(fx, fy, fd);
one_minute(cx, cy, cd);
if (vis[fx][fy][fd][cx][cy][cd]) {
ans=0; break;
}
vis[fx][fy][fd][cx][cy][cd]=true;
ans++;
}
printf("%d\n", ans);
return 0;
}
标签:ch,cur,int,代码,printf,++,3.1,include,模拟
From: https://www.cnblogs.com/ronchen/p/17580680.html