1.Cthulhu(https://codeforces.com/problemset/problem/103/B)
#include <bits/stdc++.h>
#define iter(i,x,y) for (int i = x; i <= y; i ++)
#define defN(x, y) const int y = x
#define endl(x) for (int i = 0; i < x; i ++ ) cout << endl
using namespace std;
using int64 = long long;
defN(1100, N);
int n, m;
int e[N], ne[N], h[N], idx;
bool vis[N];
void add(int a, int b)
{
e[idx] = b, ne[idx] = h[a], h[a] = idx ++;
}
void bfs(int x)
{
int q[N], hh = 0, tt = -1;
q[++ tt] = x;
while (hh <= tt) {
int t = q[hh ++];
vis[t] = true;
for (int i = h[t]; i != -1; i = ne[i]) {
if (vis[e[i]]) continue;
else q[++ tt] = e[i];
}
}
}
bool judge()
{
iter(i, 1, n) if (!vis[i]) return false;
return true;
}
void solve()
{
cin >> n >> m;
memset(h, -1, sizeof h);
iter(i, 1, m) {
int x, y;
cin >> x >> y;
add(x, y);
add(y, x);
}
bfs(1);
if (n != m || (!judge())) cout << "NO" << endl;
else cout << "FHTAGN!" << endl;
return;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int T = 1;//注意题给条件,这个T可能要初始化为1
while (T -- ) solve();
return 0;
}
2.Jumping on Walls(https://codeforces.com/problemset/problem/198/B)
#include <bits/stdc++.h>
#define iter(i,x,y) for (int i = x; i <= y; i ++)
#define defN(x, y) const int y = x
#define endl(x) for (int i = 0; i < x; i ++ ) cout << endl
using namespace std;
using int64 = long long;
typedef pair<int, int> PII;
typedef tuple<int,int,int> TRI;
typedef unsigned long long ULL;
struct pos{
int h, id, t;
};
void solve()
{
int n, k; cin >> n >> k;
vector<vector<int>> a(2);
a[0].push_back(0); a[1].push_back(0);
iter(i, 0, 1) iter(j, 1, n) {
char c; cin >> c;
if (c == 'X') a[i].push_back(1);
else if (c == '-') a[i].push_back(0);
}
//iter(i, 0, 1) iter(j, 0, n - 1) cout << a[i][j] << " \n"[j == n - 1];
queue<pos> q;
q.push((pos) {1, 0, 0}), a[0][1] = 1;
while (q.size()) {
pos t = q.front(), nw; q.pop();
nw = t; nw.h --; nw.t ++;
if (nw.h > 0 && !a[nw.id][nw.h] && nw.t < nw.h)
a[nw.id][nw.h] = 1, q.push(nw);
nw = t; nw.h ++; nw.t ++;
if(nw.h > n) {cout << "YES" << endl; return;}
if (nw.h > 0 && !a[nw.id][nw.h] && nw.t < nw.h)
a[nw.id][nw.h] = 1, q.push(nw);
nw = t; nw.h += k; nw.id = !nw.id; nw.t ++;
if(nw.h > n) {cout << "YES" << endl; return;}
if (nw.h > 0 && !a[nw.id][nw.h] && nw.t < nw.h)
a[nw.id][nw.h] = 1, q.push(nw);
}
cout << "NO" << endl;
return;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int T = 1;//注意题给条件,这个T可能要初始化为1
while (T -- ) solve();
return 0;
}