这几天小学期, 要肝程序, 晚上tm还上物理实验课就离谱, 和cf冲突, 游戏还有活动~
这几天cf只能随缘补题, 打比赛估计不可能, 和物理实验冲突
好亏啊,这场能上分
A
氵题
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef double db;
const int N = 1e5 + 5;
int n, m, _, k;
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
for (cin >> _; _; --_)
{
cin >> n;
if (n <= 3) cout << 1 << '
';
else cout << (n >> 1) << '
';
}
return 0;
}
B
看清题奥, 又公因数就行, 直接gcd == 2多简单, 最后的扔掉就行了
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef double db;
const int N = 1e5 + 5;
int n, m, _, k;
int a[2005];
int main() {
ios::sync_with_stdio(0); cin.tie(0);
for (cin >> _; _; --_) {
cin >> n;
int x = 0, y = 0;
rep (i, 1, (n << 1)) {
cin >> a[i];
if (i == (n << 1)) {
if (x == 0 && y == 0) continue;
}
if (i == (n << 1)) continue;
if (a[i] & 1) {
if (x == 0) x = i;
else cout << x << ' ' << i << '
', x = 0;
} else {
if (y == 0) y = i;
else cout << y << ' ' << i << '
', y = 0;
}
}
}
return 0;
}
C
sg函数不会写, 但和石子游戏差不多, 直接贪心也可
很明显 n = 1, A胜, n = 2 B胜
且 n & 1 == 1, 先手必胜
看看 n = 6, 6 -> 2 A胜
一个数可以因数分解成 a个奇数 和 b个偶数相乘(不考虑 1 这个因子)
通过找规律发现
1.n = 1 必败态
2.n = 2 必胜态
3.n & 1 == 1( a > 0, b = 0), 跳1, 必胜态 (n != 1)
4.当 a = 0, b > 0, A只能进行 -1 操作, 跳3, 必败态
5.当 a = 1, b = 1且这个数必为2, 要么跳2, 要么跳3, 必败态
6.当 a > 1, b = 1, 跳4, 必胜态
7.当 a > 1, b > 1, 跳4, 必胜态
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef double db;
const int N = 1e5 + 5;
int n, m, _, k;
int a[2005];
int main() {
ios::sync_with_stdio(0); cin.tie(0);
for (cin >> _; _; --_) {
cin >> n;
if (n != 2 && n % 2 == 0 && (n >> 1) & 1) {
bool flag = 0; m = n >> 1;
for (int i = 3; i * i <= m; i += 2)
if (m % i == 0) { flag = 1; break; }
if (flag) cout << "Ashishgup
";
else cout << "FastestFinger
";
}
else if (n == 1) cout << "FastestFinger
";
else if (n & 1 || n == 2) cout << "Ashishgup
";
else if ((n & n - 1) == 0) cout << "FastestFinger
";
else cout << "Ashishgup
";
}
return 0;
}
D
看一眼 a[i] 和 n 的范围, 就应该向 二分想
二分, 按要求找check就行
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef double db;
const int N = 2e5 + 5;
int n, m, _, k;
int a[N];
bool b[N], c[N];
bool check() {
int p = 0;
rep (i, 1, n)
if (p < k && c[p + 1] >= b[i]) ++p;
else if (p == k) break;
return p == k;
}
bool solve(int mid) {
rep (t, 0, 1) {
rep (i, 1, n) c[i] = (i & 1) != t;
if (check()) return true;
}
return false;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> k;
rep (i, 1, n) cin >> a[i];
int l = 1, r = 1e9 + 1;
while (l < r) {
int mid = (r + l) >> 1;
rep (i, 1, n) b[i] = a[i] > mid;
if (solve(mid)) r = mid;
else l = mid + 1;
}
cout << l;
return 0;
}
E
想象个容器, 放0, 放1, 按下标交叉放, 这个容器内的所有数一次旋转就可以弄好
查需要多少个这样的容器就行
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef double db;
const int N = 1e6 + 5;
int n, m, _, k;
char a[N], b[N];
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> a + 1 >> b + 1;
int x = 0, y = 0, c = 0, d= 0;
rep (i, 1, n) {
if (a[i] == b[i]) continue;
if (b[i] - '0') {
++x;
d ? --d, ++c : ++c;
} else {
++y;
c ? --c, ++d : ++d;
}
}
cout << (x == y ? c + d : -1);
return 0;
}
F
找时间补吧
比赛时间写不出来的, 图论太差, 让我想起了, 上次交互提看题面1h时的 恐惧