ABC448 题解
A. chmin
code
#include<bits/stdc++.h>
using namespace std;
int a[1000000];
int main(){
int N,X;
cin >> N >> X;
for(int i = 1; i <= N; ++i){
cin >> a[i];
if(a[i] < X) X = a[i], cout << "1\n";
else cout << "0\n";
}
}
B. Pepper Addiction
code
#include<bits/stdc++.h>
using namespace std;
const int NN = 1008;
int a[NN];
int main(){
int n,m;
cin >> n >> m;
for(int i = 1; i <= m; ++i)
cin >> a[i];
int ans = 0;
for(int i = 1,x,y; i <= n; ++i){
cin >> x >> y;
ans += min(a[x], y);
a[x] = max(a[x] - y, 0);
}
cout << ans;
}
C. Except and Min
code
#include<bits/stdc++.h>
using namespace std;
const int NN = 3e5 + 8;
struct Num{
int num,pos;
bool operator < (const Num &x)const{
if(num != x.num) return num < x.num;
else return pos < x.pos;
}
}a[NN];
int b[NN];
int n,q,k;
int main(){
ios::sync_with_stdio(false),cin.tie(0);
cin >> n >> q;
for(int i = 1; i <= n; ++i){
cin >> a[i].num;
a[i].pos = i;
}
sort(a+1,a+1+n);
while(q--){
cin >> k;
for(int i = 1; i <= k; ++i){
cin >> b[i];
}
int ans = k + 1;
for(int i = 1; i <= k && i <= n; ++i){
bool vis = false;
for(int j = 1; j <= k; ++j){
if(a[i].pos == b[j]){
vis = true; break;
}
}
if(!vis) {ans = i;break;}
}
cout << a[ans].num << "\n";
}
}
D. Integer-duplicated Path
做一遍 dfs,用 map 记录路径上经过的所有点的点权以及次数
code
#include<bits/stdc++.h>
using namespace std;
const int NN = 2e5 + 8;
int n;
int a[NN];
vector<int> e[NN];
map<int,int> mp;
bool ans[NN];
void dfs(int u,int fa){
++mp[a[u]];
if(mp[a[u]] > 1 || ans[fa]) ans[u] = 1;
for(auto v : e[u]){
if(v == fa) continue;
dfs(v,u);
}
--mp[a[u]];
}
int main(){
ios::sync_with_stdio(false),cin.tie(0);
cin >> n;
for(int i = 1; i <= n; ++i)
cin >> a[i];
for(int i = 1,u,v; i <= n-1; ++i){
cin >> u >> v;
e[u].push_back(v);
e[v].push_back(u);
}
dfs(1,0);
for(int i = 1; i <= n; ++i){
if(ans[i]) cout << "Yes\n";
else cout << "No\n";
}
}
E. Simple Division
\[\lfloor \frac N M\rfloor \mod 10007 = \lfloor \frac {N \mod (M\times 10007)} M\rfloor
\]
这样就可以使用快速幂等手段迅速计算了
code
#include<bits/stdc++.h>
using namespace std;
const int MOD = 10007;
typedef long long ll;
int k,m;
ll mod;
ll ksm(ll x, ll p){
ll res = 1;
while(p){
if(p&1) res = res * x % mod;
x = x * x % mod;
p >>= 1;
}
return res;
}
ll modify(ll c,ll l){
ll res = 0;
ll x = 10;
ll now = 1;
while(l){
if(l & 1) res = (res * x + now) % mod;
now = now * (x+1) % mod;
x = x * x % mod;
l >>= 1;
}
return res * c % mod;
}
int main(){
ios::sync_with_stdio(false),cin.tie(0);
cin >> k >> m;
mod = MOD * m;
ll now = 0;
for(int i = 1,c,l; i <= k; ++i){
cin >> c >> l;
now = now * ksm(10,l) % mod;
now = now + modify(c,l);
now %= mod;
// cout << modify(c,l) << ":" << now << endl;
}
cout << now / m;
// cout << mod;
}
F. Authentic Traveling Salesman Problem
tag: 构造
我们可以按列进行分块,每次一列弄完弄下一列
设列宽为B,\(T = 2\times 10^7\)
则总长度为:\(\frac {T^2} B + NB\leq 2T\sqrt N\approx 8.8\times 10^9\)
code
```#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll T = 2e7 + 8, NN = 6e4 + 8;
const ll B = T / sqrt(NN);
int n;
struct Node{
int x,y;
int num;
bool operator < (const Node &A)const{
if(x/B != A.x / B) return x/B < A.x/B;
int block = x/B;
return (block&1) ? y > A.y : y < A.y;
}
}node[NN];
int main(){
ios::sync_with_stdio(false),cin.tie(0);
cin >> n;
for(int i = 1; i <= n; ++i){
cin >> node[i].x >> node[i].y;
node[i].num = i;
}
sort(node+2,node+1+n);
for(int i = 1; i <= n; ++i) cout << node[i].num << " ";
}
</details>
## G. Conquest
tag: `博弈论`
本文来自博客园,作者:ricky_lin,转载请注明原文链接:https://www.cnblogs.com/rickylin/p/19687650/ABC448

浙公网安备 33010602011771号