A. Calandar
直接把每个日期换算成多少天 然后看差值是多少个一周(五天)的周期 然后算一下
code:
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[5] = {1,2,3,4,5};
void solve(){
int y1,m1,d1; string s1; cin >> y1 >> m1 >> d1 >> s1;
int y2,m2,d2; cin >> y2 >> m2 >> d2;
map<string,int> mp;
mp["Monday"] = 0,mp["Tuesday"] = 1,mp["Wednesday"] = 2;
mp["Thursday"] = 3,mp["Friday"] = 4;
map<int,string> mp2;
for(auto x : mp){
mp2[x.second] = x.first;
}
int sum1 = y1 * 12 * 30 + m1 * 30 + d1;
int sum2 = y2 * 12 * 30 + m2 * 30 + d2;
if(sum1 < sum2){
int cnt = sum2 - sum1;
cnt %= 5;
int x = mp[s1];
x = (x + cnt) % 5;
cout << mp2[x] << endl;
} else{
int cnt = sum1 - sum2;
cnt %= 5;
int x = mp[s1];
x = (x + 5 - cnt) % 5;
cout << mp2[x] << endl;
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int t; cin >> t;
while(t --){
solve();
}
return 0;
}
C. Wandering Robot
显而易见 第一次最后的坐标如果为 (x,y) 那么 k 次的坐标就为 (x * k,y * k)
那么算出 第 k - 1 次的坐标 然后以第 k - 1 次坐标为起点开始再跑一次 看期间最大值即可
code:
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,k;
void solve(){
cin >> n >> k;
string s; cin >> s;
int mx = -1;
int x = 0,y = 0;
for(int i = 0;i < n;i ++){
if(s[i] == 'L') x --;
else if(s[i] == 'R') x ++;
else if(s[i] == 'U') y --;
else y ++;
mx = max(mx,abs(x) + abs(y));
}
int xx = x * (k - 1),yy = y * (k - 1);
int ans = mx;
if(k == 1){
cout << ans << endl;
return;
}
for(int i = 0;i < n;i ++){
if(s[i] == 'L') xx --;
else if(s[i] == 'R') xx ++;
else if(s[i] == 'U') yy --;
else yy ++;
ans = max(ans,abs(xx) + abs(yy));
}
cout << ans << endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int t; cin >> t;
while(t --){
solve();
}
return 0;
}
D. Game on a Graph
n 个点联通一块 最少需要 n - 1 条边 那么m - (n - 1) 条边都是多余可以随便删除的边 直接看这些条边删除完看该谁 则谁队输 输出赢得队伍
code:
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,k;
void solve(){
cin >> k;
string s; cin >> s;
cin >> n >> m;
for(int i = 0;i < m;i ++){
int u,v; cin >> u >> v;
}
int cnt = m - n + 1;
int pos = cnt % k;
if(s[pos] == '1') cout << 2 << endl;
else cout << 1 << endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int t; cin >> t;
while(t --){
solve();
}
return 0;
}
F. Stones in the Bucket
实际看下降到 avg 的操作次数
code:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 7;
int a[N];
int n;
void solve(){
cin >> n;
int sum = 0;
for(int i = 0;i < n;i ++){
cin >> a[i];
sum += a[i];
}
if(n == 1){
cout << 0 << endl;
return;
}
int avg = sum / n;
int ans = 0;
for(int i = 0;i < n;i ++){
if(a[i] > avg) ans += a[i] - avg;
}
cout << ans << endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int t; cin >> t;
while(t --){
solve();
}
return 0;
}
L. Median
a
1
>
a
2
则可以建立
1
通向
2
的单向路
{a_1 > a_2 则可以建立 1 通向 2的单向路 }
a1>a2则可以建立1通向2的单向路
然后每个点跑 bfs 来看有没有环并单次更新他能到的点的之前和这个点之后的个数
因为会有 1->2 , 2->3 , 1->4 , 4->3 类似这种
这种统计出的 比如 点2 2之前的数有 1 个 后面的数有 2 个 但是对于 4 来说 他既可以大于 2 ,也可以小于 2
所以只要大于一个点的个数和小于的个数都 <= n / 2 即可
code:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e2 + 7;
int n,m;
vector<int> g[N];
int st[N];
int pre[N],suf[N];
int bfs(int x){
for(int i = 0;i <= n;i ++) st[i] = 0;
queue<int> q;
q.push(x);
while(q.size()){
int t = q.front();
q.pop();
if(st[t] && t == x) return 0;
for(auto u : g[t]){
if(u == x) return 0;
if(st[u]) continue;
q.push(u);
st[u] = 1;
pre[u] ++,suf[x] ++;
}
}
return 1;
}
void solve(){
for(int i = 0;i < N;i ++){
g[i].clear();
st[i] = pre[i] = suf[i] = 0;
}
cin >> n >> m;
for(int i = 0;i < m;i ++){
int u,v; cin >> u >> v;
g[u].push_back(v);
}
for(int i = 1;i <= n;i ++){
int flag = bfs(i);
if(!flag){
for(int i = 1;i <= n;i ++) cout << 0;
cout << endl;
return;
}
}
int ans = 0;
for(int i = 1;i <= n;i ++){
if(pre[i] <= n / 2 && suf[i] <= n / 2) cout << 1;
else cout << 0;
}
cout << endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int t; cin >> t;
while(t --){
solve();
}
return 0;
}
M. Sekiro
每次 / 2 最多超不过 32次 直接取 min(32,k) 跑暴力即可
code:
#include<bits/stdc++.h>
#define int long long
using namespace std;
void solve(){
int n,k; cin >> n >> k;
for(int i = 0;i < min((int)32,k);i ++){
n = (n + 1) / 2;
}
cout << n << endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int t; cin >> t;
while(t --){
solve();
}
return 0;
}