版权声明:while (!success) try(); https://blog.csdn.net/qq_35850147/article/details/89293647
2017 ECNA Regional Contest
题目
链接: https://pan.baidu.com/s/1EACO23Tlp83df59WkzP0mQ 提取码: uvrr
题解
Problem C DRM Messages
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin >> s;
string s1 = s.substr(0, s.length() / 2);
string s2 = s.substr(s.length() / 2);
int sum1 = 0, sum2 = 0;
for (int i = 0; i < s.length() / 2; i++)
{
sum1 += s1[i] - 'A';
sum2 += s2[i] - 'A';
}
for (int i = 0; i < s.length() / 2; i++)
{
s1[i] = (s1[i] - 'A' + sum1) % 26 + 'A';
s2[i] = (s2[i] - 'A' + sum2) % 26 + 'A';
s1[i] = (s1[i] - 'A' + s2[i] - 'A') % 26 + 'A';
}
cout << s1 << endl;
return 0;
}
Problem D Game of Throwns
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, m;
stack<int> ope;
cin >> n >> m;
int pos = 0;
while (m--)
{
string s;
cin >> s;
if (s == "undo")
{
cin >> s;
int u = stoi(s);
while (u-- && !ope.empty())
ope.pop();
}
else
ope.push(stoi(s));
}
while (!ope.empty())
{
pos += ope.top();
ope.pop();
}
while (pos < 0)
pos += n;
cout << pos % n << endl;
return 0;
}
Problem H Sheba’s Amoebas
#include <bits/stdc++.h>
using namespace std;
int a, b;
char m[101][101];
const int dx[] = {0, 0, 1, 1, 1, -1, -1, -1};
const int dy[] = {1, -1, 0, 1, -1, 0, 1, -1};
struct cor
{
int x, y;
};
bool vis[101][101];
bool is_inside(int i, int j)
{
return i >= 1 && i <= a && j >= 1 && j <= b ? true : false;
}
bool BFS(int i, int j)
{
bool flag = true;
queue<cor> q;
q.push(cor{i, j});
while (!q.empty())
{
cor c = q.front();
q.pop();
vis[c.x][c.y] = true;
int cnt = 0;
for (int k = 0; k < 8; k++)
if (is_inside(c.x + dx[k], c.y + dy[k] && m[c.x + dx[k]][c.y + dy[k]] == '#'))
{
cnt++;
if (!vis[c.x + dx[k]][c.y + dy[k]])
q.push(cor{c.x + dx[k], c.y + dy[k]});
}
if (cnt != 2)
flag = false;
}
return flag ? true : false;
}
int main()
{
scanf("%d%d", &a, &b);
getchar();
for (int i = 1; i <= a; i++)
{
for (int j = 1; j <= b; j++)
m[i][j] = getchar();
getchar();
}
int ans = 0;
for (int i = 1; i <= a; i++)
for (int j = 1; j <= b; j++)
if (!vis[i][j] && m[i][j] == '#')
ans += BFS(i, j);
printf("%d\n", ans);
return 0;
}