闲话
康复一周任然能在 T1 卡半小时的神人。
正文
- 学历史导致的
题面。
由于是康复第一题,所以比较简单。直接暴力算。
#include<bits/stdc++.h>
using namespace std;
const string tian[20] = {"jia", "yi", "bing", "ding", "wu", "ji", "geng", "xin", "ren", "gui"},
di[20] = {"zi", "chou", "yin", "mao", "chen", "si", "wu", "wei", "shen", "you", "xu", "hai"};
unordered_map<string, int> mp;
int t, ti = 0, zi = 0;
string s;
int main() {
for (int i = 1; i <= 60; i++) {
mp[tian[ti % 10] + di[zi % 12]] = i;
// cout << 1983 + i << ' ' << tian[ti % 10] + di[zi % 12] << '\n';
ti++, zi++;
}
cin >> t;
while (t--) {
cin >> s;
cout << mp[s] + 1983;
}
return 0;
}- 学 DP 导致的
题面。
这道题一会儿就打出来了,我还庆幸自己居然记得点东西。结果调到比赛结束都没调好。最终在同机房的 lr 大佬帮助下修改成功。
表示最后一个字母为 的最大长度。然后因为答案最大为 ,所以如果 ,就把 定为 即可。
#include<bits/stdc++.h>
using namespace std;
int t, a[5050], n, dp[5020];
string s, k,q;
int main() {
//~ ios::sync_with_stdio(0);
//~ cin.tie(0); cout.tie(0);
cin >> t;
while (t--) {
s = "", k = "", q = "";
cin >> s >> k;
q=s;
//cout << q;
if(k.size()>2||(k!="1"&&k!="2"&&k!="3"&&k!="4"&&k!="5"&&k!="6"&&k!="7"&&k!="8"&&k!="9"&&k!="10"&&k!="11"&&k!="12"&&k!="13"&&k!="14"&&k!="15"&&k!="16"&&k!="17"&&k!="18"&&k!="19"&&k!="20"&&k!="21"&&k!="22"&&k!="23"&&k!="24"&&k!="25")) k="26";
int p=stoi(k);
for(int i=2;i<=p;i++) s=s+q;
//cout << s;
n = s.size();
for (int i = 0; i < n; i++) {
a[i + 1] = s[i] - 'a' + 1;
}
//cout << "\n" << s << '\n';
for (int i = 1; i <= n; i++) {
for (int j = 0; j < a[i]; j++) {
dp[a[i]] = max(dp[j] + 1, dp[a[i]]);
}
}
int ans = -1;
for (int i = 1; i <= 'z' - 'a' + 1; i++) {
ans = max(ans, dp[i]);
dp[i] = 0;
}
cout << ans << '\n';
}
return 0;
}后来打了 Acgo 的比赛,但用的是老师女儿的账号,家里登不上,就不写了。反正打小学组我也罚时了两发。
- P11500 [ROIR 2019] 间歇训练 (Day 2)
题面。
回家自己打了这道题。因为个人比较喜欢 DP,所以打了这道。先打了记忆化搜索的试试感觉,然后打了普通 DP 的。最后观察 tag,所以用了前缀和优化。
#include <bits/stdc++.h>
using namespace std;
const int N = 5005, mod = 1e9 + 7;
int n, k, dp[N][N][2], srr[N][2];
int main() {
cin >> n >> k;
if (n == k) {
cout << 1;
return 0;
}
dp[k][k][0] = dp[k][k][1] = 1;
for (int i = k + 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
srr[i - j][1] += dp[i - j][j - 1][1];
srr[i - j][1] %= mod;
dp[i][j][0] += srr[i - j][1];
dp[i][j][0] %= mod;
if (j == 1)
for (int l = j + 1; l <= i - j; l++) {
srr[i - j][0] += dp[i - j][l][0];
srr[i - j][0] %= mod;
}
if (i - j >= j + 1) {
srr[i - j][0] -= dp[i - j][j][0];
srr[i - j][0] %= mod;
dp[i][j][1] += srr[i - j][0];
dp[i][j][1] %= mod;
}
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
ans += (dp[n][i][1] + dp[n][i][0]) % mod;
ans %= mod;
}
cout << ans;
return 0;
}- 序列重排
普及组 T1 难度我卡了半小时。。。。
题面。
判断下情况输出 、 或 即可。
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int n, a[N], ze = 0, tt = -1, last;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] == 0) ze++;
tt = max(tt, a[i]);
}
if (ze <= (n + 1) / 2) cout << 0;
else {
if (tt > 1)cout << 1;
else if (ze == n) cout << 1;
else cout << 2;
}
return 0;
}- 划分
题面。
也卡了有一回。证明:
其中 , 表示 、 的最大公因数。
(很蠢的肉眼感性证明)
随后我辗转相除法炸了。。。。。。
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
//int gcd(int a, int b) {
// if (a == 0) return b;
// return gcd(b % a, a);
//}
int n;
long long a[N], srr[N], rrr[N];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
srr[i] = srr[i - 1] + a[i];
}
for (int i = n; i >= 1; i--) {
rrr[i] = rrr[i + 1] + a[i];
}
long long ans = -1;
for (int i = 1; i < n; i++) {
ans = max(ans, __gcd(srr[i], rrr[i + 1]));
}
cout << ans;
return 0;
}- 蛋糕
题面。
感觉很暴力。。。但我 了。
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 7;
unordered_map<long long, int> mp, mpp;
int m;
long long n, a[N], sum = 0;
signed main() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> a[i];
mp[a[i]]++;
sum += a[i];
}
if (n > sum) {
cout << -1;
return 0;
}
long long cnt = 0, t = 0, ans= 0;
int k = 0, kk = 0;
for (long long i = n; i > 0; i /= 2, k++) {
if (i % 2 == 1) {
// cout << i << ' ';
cnt = 0;
t = pow(2, k);
for (long long j = pow(2, k); j > 0; j /= 2) {
cnt += j * mp[j];
}
if (cnt >= t) {
for (long long j = pow(2, k); j > 0; j /= 2) {
kk = mp[j];
mp[j] -= min(1ll * kk, t / j);
t -= min(1ll * kk, t / j) * j;
}
} else {
kk = 0;
for (long long j = pow(2, k + 1); j <= 1e18 + 1; j *= 2) {
kk++;
if (mp[j]) {
ans += kk;
mp[j]--;
mp[pow(2, k)] += pow(2, kk) - 1;
break;
}
}
}
// cout << '\n';
}
}
cout << ans;
return 0;
}