Luogu
P1042 [NOIP2003 普及组] 乒乓球
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int s[62505], ddl[3];
int t;
void init() {
ddl[1] = 11, ddl[2] = 21;
}
int main() {
init();
while (1) {
char tmp;
cin >> tmp;
if (tmp == 'W') s[++t] = 1;
else if (tmp == 'L') s[++t] = 0;
else if (tmp == 'E') break;
}
for (int k = 1; k <= 2; k++) {
int l = 0, r = 0;
for (int i = 1; i <= t; i++) {
l += s[i], r += (1 - s[i]);
if (max(l, r) >= ddl[k] && abs(l - r) >= 2) {
cout << l << ":" << r << '\n';
l = r = 0;
}
}
cout << l << ":" << r << '\n';
cout << '\n';
}
return 0;
}
P2670 [NOIP2015 普及组] 扫雷游戏
#include <iostream>
#include <cstdio>
using namespace std;
const int dx[10] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy[10] = {-1, 0, 1, -1, 1, -1, 0, 1};
int n, m;
char edge[105][105];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> edge[i][j];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
int cnt = 0;
if (edge[i][j] == '*')
cout << "*";
else {
for (int k = 0; k < 8; k++)
if (edge[i+dx[k]][j+dy[k]] == '*')
cnt++;
cout << cnt;
}
}
cout <<'\n';
}
return 0;
}
P1563 [NOIP2016 提高组] 玩具谜题
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n, m, now = 1;
struct node {
int cx;
string job;
}er[100005];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> er[i].cx, cin >> er[i].job;
while (m -- ) {
int opt, num;
cin >> opt >> num;
if (opt == 0) {
if(er[now].cx == 0) {
now -= num;
if (now <= 0) now += n;
}
else if (er[now].cx == 1) {
now += num;
if (now > n) now -= n;
}
}
else if (opt == 1) {
if (er[now].cx == 0) {
now += num;
if (now > n) now -= n;
}
else if (er[now].cx == 1) {
now -= num;
if (now <= 0) now += n;
}
}
}
cout << er[now].job;
return 0;
}
标签:tmp,now,int,Day1,cx,include,模拟,er
From: https://www.cnblogs.com/Gmor-cerr-blog/p/17765579.html