A - Chuanpai
铁签 枚举即可
code:
#include<bits/stdc++.h>
using namespace std;
void solve(){
int k; cin >> k;
int ans = 0;
for(int i = 1;i <= 6;i ++){
for(int j = 1;j <= 6;j ++){
if(i > j) continue;
int cnt = i + j;
if(cnt == k) ans ++;
}
}
cout << ans << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int t; cin >> t;
while(t --){
solve();
}
return 0;
}
B - Hotpot
易发现假设喜好同类型的人数为偶数 那么无论几轮 获得幸福感的人都是同样的 如果是奇数 可以发现两轮下来又回到了初始状态
所以无论喜好同类型的人数是奇数还是偶数 两轮都会回到最初状态 那么就先看有几个两轮 然后直接遍历剩下的 m 即可
code:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 7;
int a[N];
int n,k,m;
void solve(){
cin >> n >> k >> m;
for(int i = 0;i < n;i ++) cin >> a[i];
int cnt1 = m / n;
int cnt2 = m % n;
map<int,int> ans,mp;
for(int i = 0;i < 2 * n;i ++){
if(mp[a[i % n]]) ans[i % n] ++,mp[a[i % n]] = 0;
else mp[a[i % n]] = 1;
}
int cnt = cnt1 / 2;
if(cnt){
for(int i = 0;i < n;i ++) ans[i % n] *= cnt;
if(cnt1 & 1){
mp.clear();
for(int i = 0;i < n + cnt2;i ++){
if(mp[a[i % n]]) ans[i % n] ++,mp[a[i % n]] = 0;
else mp[a[i % n]] = 1;
}
} else{
for(int i = 0;i < cnt2;i ++){
if(mp[a[i % n]]) ans[i % n] ++,mp[a[i % n]] = 0;
else mp[a[i % n]] = 1;
}
}
} else{
mp.clear();
ans.clear();
for(int i = 0;i < m;i ++){
if(mp[a[i % n]]) ans[i % n] ++,mp[a[i % n]] = 0;
else mp[a[i % n]] = 1;
}
}
cout << ans[0];
for(int i = 1;i < n;i ++) cout << " " << ans[i];
cout << endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int t; cin >> t;
while(t --){
solve();
}
return 0;
}
D - Rock Paper Scissors
直接枚举 BaoBao 会出的牌 然后按 DreamGrid 拥有的牌出 他最希望的是分数+1的情况 其次是0 最后是 1 依次枚举即是最优
code:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e1 + 7;
int a[N],b[N];
int n,k,m;
void solve(){
for(int i = 0;i < 3;i ++) cin >> a[i];
for(int i = 0;i < 3;i ++) cin >> b[i];
int ans = 0;
for(int i = 0;i < 3;i ++){
if(!a[i]) continue;
if(i == 0){
if(b[1] && a[i]){
int cnt = min(b[1],a[i]);
ans += cnt;
b[1] -= cnt;
a[i] -= cnt;
}
}
if(i == 1){
if(b[2] && a[i]){
int cnt = min(b[2],a[i]);
ans += cnt;
b[2] -= cnt;
a[i] -= cnt;
}
}
if(i == 2){
if(b[0] && a[i]){
int cnt = min(b[0],a[i]);
ans += cnt;
b[0] -= cnt;
a[i] -= cnt;
}
}
}
for(int i = 0;i < 3;i ++){
if(!a[i]) continue;
if(i == 0){
if(a[i] && b[0]){
int cnt = min(b[0],a[i]);
b[0] -= cnt;
a[i] -= cnt;
}
}
if(i == 1){
if(a[i] && b[1]){
int cnt = min(b[1],a[i]);
b[1] -= cnt;
a[i] -= cnt;
}
}
if(i == 2){
if(a[i] && b[2]){
int cnt = min(b[2],a[i]);
b[2] -= cnt;
a[i] -= cnt;
}
}
}
for(int i = 0;i < 3;i ++) ans -= b[i];
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;
}
H - Nihongo wa Muzukashii Desu
按情况模拟即可
code:
#include<bits/stdc++.h>
#define int long long
using namespace std;
vector<pair<string, string>> v = {
{"shimasu","shite"},{"chimasu","tte"},{"rimasu","tte"},
{"mimasu","nde"},{"bimasu","nde"},{"nimasu","nde"},
{"kimasu","ite"},{"gimasu","ide"},{"imasu","tte"}
};
void solve(){
string s; cin >> s;
if(s == "ikimasu"){
cout << "itte" << endl;
return;
}
for(auto x : v){
if(x.first.size() > s.size()) continue;
string cnt = s.substr(s.size() - x.first.size());
if(cnt == x.first){
cout << s.substr(0,s.size() - x.first.size()) << x.second << endl;
return;
}
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int t; cin >> t;
while(t --){
solve();
}
return 0;
}
K - K-skip Permutation
模拟即可
code:
#include<bits/stdc++.h>
#define int long long
using namespace std;
void solve(){
int n,k; cin >> n >> k;
vector<int> v;
map<int,int> mp;
int sum = 0;
for(int i = 1;i <= n;){
if(mp[i]) i ++,sum ++;
else{
int j = i;
while(j <= n){
v.push_back(j);
mp[j] = 1;
j += k;
sum ++;
}
}
}
cout << v[0];
for(int i = 1;i < v.size();i ++) cout << " " << v[i];
cout << endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int t; t = 1;
while(t --){
solve();
}
return 0;
}
L - Spicy Restaurant
首先可以发现辣度最大也就 100 那么就可以对每个辣度进行 bfs 得到 d[n][ w i {w_i} wi] 即辣度为 w i {w_i} wi到达点 n
的距离 bfs时把辣度低于 w i {w_i} wi的点都push进queue 然后进行bfs看辣度符合的到其他点的最短距离即可
code:
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n,m,q;
int d[N][110];
int w[N];
vector<int> g[N];
void bfs(int x){
queue<int> q;
for(int i = 1;i <= n;i ++){
if(w[i] <= x){
d[i][x] = 0;
q.push(i);
}
}
vector<int> st(n + 1,0);
while(q.size()){
int t = q.front();
q.pop();
if(st[t]) continue;
st[t] = 1;
for(int u : g[t]){
if(st[u]) continue;
if(d[u][x] > d[t][x] + 1){
d[u][x] = d[t][x] + 1;
q.push(u);
}
}
}
}
void solve(){
cin >> n >> m >> q;
memset(d,0x3f,sizeof d);
for(int i = 1;i <= n;i ++) cin >> w[i];
for(int i = 1;i <= m;i ++){
int u,v; cin >> u >> v;
g[u].push_back(v),g[v].push_back(u);
}
for(int i = 1;i <= 100;i ++) bfs(i);
while(q --){
int p,a; cin >> p >> a;
int ans = 0x3f3f3f3f;
for(int i = 1;i <= a;i ++) ans = min(ans,d[p][i]);
if(ans == 0x3f3f3f3f) ans = -1;
cout << ans << endl;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int t; t = 1;
while(t --){
solve();
}
return 0;
}
M - True Story
因为只有知道自己能到 才会出发 所以直接看每次通知推迟跟着推迟到的时间 ( p i − t i ) {(p_i - t_i)} (pi−ti) 取最大值
然后去看每个人的速度够不够到达即可
code:
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n,m,q;
int d[N][110];
int w[N];
vector<int> g[N];
void bfs(int x){
queue<int> q;
for(int i = 1;i <= n;i ++){
if(w[i] <= x){
d[i][x] = 0;
q.push(i);
}
}
vector<int> st(n + 1,0);
while(q.size()){
int t = q.front();
q.pop();
if(st[t]) continue;
st[t] = 1;
for(int u : g[t]){
if(st[u]) continue;
if(d[u][x] > d[t][x] + 1){
d[u][x] = d[t][x] + 1;
q.push(u);
}
}
}
}
void solve(){
cin >> n >> m >> q;
memset(d,0x3f,sizeof d);
for(int i = 1;i <= n;i ++) cin >> w[i];
for(int i = 1;i <= m;i ++){
int u,v; cin >> u >> v;
g[u].push_back(v),g[v].push_back(u);
}
for(int i = 1;i <= 100;i ++) bfs(i);
while(q --){
int p,a; cin >> p >> a;
int ans = 0x3f3f3f3f;
for(int i = 1;i <= a;i ++) ans = min(ans,d[p][i]);
if(ans == 0x3f3f3f3f) ans = -1;
cout << ans << endl;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int t; t = 1;
while(t --){
solve();
}
return 0;
}