【杭电多校训练记录】 2025"钉耙编程"中国大学生算法设计春季联赛(1)
训练情况

赛后反思
成功戳到我博弈论的短板了,被初中生薄纱了,题目好难且罚时吃满
1001 签到
很签到的签到题,我们直接判断给出的名字是否相同,相同输出第几位即可,都没有输出 -1
点击查看代码
#include <bits/stdc++.h>
// #define int long long
#define endl '\n'
using namespace std;
void solve(){
int n; string s;
cin>>n>>s;
int ans = 0;
for(int i = 1;i<=n;i++){
string x; cin>>x;
if(x == s){
ans = i;
}
}
if(ans) cout<<ans<<endl;
else cout<<-1<<endl;
}
signed main(){
int T; cin>>T; while(T--)
solve();
return 0;
}
1006 密码
貌似是热身赛的题改编来的,首先我们对于一个一元方程判断是否有非负整数解,我们只需要移项反解出 \(x\),\(x = \frac{c-b}{a}\),所以 \(c-b\) 一定得是 \(a\) 的倍数,所以我们直接枚举 \(u,v,w\) 对应 \(a,b,c\) 的关系,判断有几个解记录一下,对于整个方程组因为存在唯一解,所以是刚好出现 \(n\) 次的解
点击查看代码
#include <bits/stdc++.h>
// #define int long long
#define endl '\n'
using namespace std;
void solve(){
int n; cin>>n;
vector<int> a(n + 1),b(n + 1),c(n + 1);
set<int> ans[n+1];
for(int i = 1;i<=n;i++){
cin>>a[i]>>b[i]>>c[i];
if((a[i] - b[i])%c[i] == 0) ans[i].insert((a[i]-b[i])/c[i]);
if((b[i] - a[i])%c[i] == 0) ans[i].insert((b[i]-a[i])/c[i]);
if((a[i] - c[i])%b[i] == 0) ans[i].insert((a[i]-c[i])/b[i]);
if((c[i] - a[i])%b[i] == 0) ans[i].insert((c[i]-a[i])/b[i]);
if((b[i] - c[i])%a[i] == 0) ans[i].insert((b[i]-c[i])/a[i]);
if((c[i] - b[i])%a[i] == 0) ans[i].insert((c[i]-b[i])/a[i]);
}
map<int,int> v;
for(int i = 1;i<=n;i++){
for(auto j:ans[i]){
if(j>=0) v[j]++;
}
}
for(auto i:v){
if(i.second == n){
cout<<i.first<<endl;
return;
}
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int T; cin>>T; while(T--)
solve();
return 0;
}

浙公网安备 33010602011771号