A - Edge Checker
题意:已知一个环,给你两个点 a a a 和 b b b ,问你这两个点之间有没有边
做法:随便写,意思到位就行
#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 100010;
int t, n, m;
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
int a, b;
cin >> a >> b;
if ((a == 10 && b == 1) || (a == 1 && b == 10)) puts("Yes");
else if (abs(a - b) == 1) puts("Yes");
else puts("No");
return 0;
}
B - Count Distinct Integers
题意:给你一些数,问不重复数字的个数
做法,用集合直接去重输出大小就行
#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 100010;
int t, n, m;
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
set<int> s;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
s.insert(x);
}
cout << s.size() << endl ;
return 0;
}
C - Jumping Takahashi
题意:初始在0,可以走 n n n 步,每一次要么走 a a a 要么走 b b b ,问能否走完 n n n 步后到达 x x x
做法:暴力剪枝,同一步走到相同位置的删掉,超过 x x x 的删掉即可
#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 110;
int t, n, m;
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
vector<int> A, B;
A.push_back(0);
B.push_back(0);
for (int i = 0; i < n; i++)
{
int a, b;
cin >> a >> b;
unordered_set<int> S1, S2;
vector<int> C, D;
for (int i = 0; i < A.size(); i++)
{
int na = A[i] + a;
int nb = A[i] + b;
if (na <= m && !S1.count(na)) {
C.push_back(na);
S1.insert(na);
}
if (nb <= m && !S1.count(nb)) {
C.push_back(nb);
S1.insert(nb);
}
}
for (int i = 0; i < B.size(); i++)
{
int na = B[i] + a;
int nb = B[i] + b;
if (na <= m && !S2.count(na)) {
D.push_back(na);
S2.insert(na);
}
if (nb <= m && !S2.count(nb)) {
D.push_back(nb);
S2.insert(nb);
}
}
A = C;
B = D;
}
if (count(A.begin(), A.end(), m) || count(B.begin(), B.end(), m)) puts("Yes");
else puts("No");
return 0;
}
D - Strange Balls
题意:给定 n n n 个球,每个球都有一个权值,每次往柱子里放小球,如果连续 i i i 个权值为 i i i 的球就会抵消掉,让你输出放入第 i i i 个球后的体积
做法:模拟,开一个 p a i r pair pair 数组用来记录放入第 i i i 个球时,前面有多少个和它权值相同的球
#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 100010;
int t, n, m;
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
vector<pair<int, int>> a;
for (int i = 0; i < n; i++)
{
cin >> m;
int cnt;
if (a.empty() || a.back().first != m) cnt = 1;
else cnt = a.back().second + 1;
a.push_back({m, cnt});
if (a.back().second == m)
{
while (m--)
{
a.pop_back();
}
}
cout << a.size() << endl ;
}
return 0;
}