Codeforces Round #800 (Div. 2 + Div. 1) A - E

比赛链接

1|0A

核心思路

经典的构造方式;010101这样构造就好了。

// Problem: A. Creep // Contest: Codeforces - Codeforces Round #800 (Div. 2) // URL: https://codeforces.com/contest/1694/problem/A // Memory Limit: 256 MB // Time Limit: 1000 ms // // Powered by CP Editor (https://cpeditor.org) #define _CRT_SECURE_NO_WARNINGS #include<bits/stdc++.h> using namespace std; typedef long long LL; #define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) #define NO {puts("NO") ; return ;} #define YES {puts("YES") ; return ;} #define endl "\n" #define int long long void solve() { int a,b; cin>>a>>b; vector<int> ans; while(a&&b) { if(a) { ans.push_back(0); a--; } if(b) { ans.push_back(1); b--; } } if(a) { for(int i=0;i<a;i++) ans.push_back(0); } else { for(int i=0;i<b;i++) ans.push_back(1); } for(int i=0;i<ans.size();i++) cout<<ans[i]; cout<<endl; } signed main() { int T; cin>>T; while(T--) { solve(); } }

2|0B

核心思路

又是经典的从最开始的部分来发现规律和挖掘性质。

我们可以发现如果是01,我们往有点添加0还是1都是没有影响的。 也就是:001 101 因为如果是第一种情况,只需要使用性质1就好了。 如果是第二种情况那么使用下性质2在使用性质1就好了。这些都是可以化简为我们想要的要样子的。 所以啊,我们就挖掘出来了一个重要的性质:只要有不相同的数那么以这个为起点的区间都是成立的。 一般b题不会很难的,挖掘出来这个性质就差不多了。hhh
// Problem: B. Paranoid String // Contest: Codeforces - Codeforces Round #800 (Div. 2) // URL: https://codeforces.com/contest/1694/problem/B // Memory Limit: 256 MB // Time Limit: 1000 ms // // Powered by CP Editor (https://cpeditor.org) #define _CRT_SECURE_NO_WARNINGS #include<bits/stdc++.h> using namespace std; typedef long long LL; #define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) #define NO {puts("NO") ; return ;} #define YES {puts("YES") ; return ;} #define endl "\n" #define int long long void solve() { int n; string s; cin>>n>>s; int ans=n; for(int i=1;i<n;i++) { if(s[i-1]!=s[i]) ans+=i; } cout<<ans<<endl; } signed main() { int T; cin>>T; while(T--) { solve(); } }

3|0C

核心思路

这个题目咋一看不怎么好像,所以我们得先把题目化简:我们把第一种操作定义为b[i],第二种为c[i],然后我们想要构造的数组为a[i].

所以a[i]=b[i]c[i],我们还可以根据最后会回到原点,在挖掘出来一条性质:c[i]=b[i1].

所以a[i]=b[i]b[i1].

然后我们再回到实际范围找出b数组的约束条件,首先b[i]0.因为操作数不可能为负数。然后我们如果发现某一个是0,那么后面的b也肯定是0,因为如果点b[i]=0.就说明我们的指针压根没有到这个点,那么这个点之后的点也肯定不会到。

总的来说,这道题还是有一点难度的。

// Problem: C. Directional Increase // Contest: Codeforces - Codeforces Round #800 (Div. 2) // URL: https://codeforces.com/contest/1694/problem/C // Memory Limit: 256 MB // Time Limit: 1000 ms // // Powered by CP Editor (https://cpeditor.org) #define _CRT_SECURE_NO_WARNINGS #include<bits/stdc++.h> using namespace std; typedef long long LL; #define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) #define NO {puts("NO") ; return ;} #define YES {puts("YES") ; return ;} #define endl "\n" #define int long long const int N=1e6+10; int a[N],b[N]; void solve() { int n; cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=n;i++) b[i]=b[i-1]+a[i]; if(b[n]!=0) { cout<<"No"<<endl; return; } int flag=0; for(int i=1;i<=n;i++) { if(b[i]<0) flag=1; } int zero=0; for(int i=1;i<=n;i++) { if(b[i]==0) { zero=1; } else if(zero) { flag=1; } } if(flag) { NO; } else { YES; } } signed main() { int T; cin>>T; while(T--) { solve(); } }

4|0D

题目

其实看他花里胡哨搞一堆,就是如果我们对子节点加了c,那么父节点也会相应的加c。

核心思路

首先一个父节点当前的sum值是来源于他的儿子的:g(u)=v>son(u)r(v).如果g(u)还是小于l[u],那么就需要单独加一次。然后更新下r[u]就好了,一定要注意r[u]只可以来源于他的儿子。所以只需要和sum去一个最小值就好了。

时间复杂度O(n)

// Problem: D. Fake Plastic Trees // Contest: Codeforces - Codeforces Round #800 (Div. 2) // URL: https://codeforces.com/contest/1694/problem/D?mobile=true // Memory Limit: 256 MB // Time Limit: 1000 ms // // Powered by CP Editor (https://cpeditor.org) #define _CRT_SECURE_NO_WARNINGS #include<bits/stdc++.h> using namespace std; typedef long long LL; #define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) #define NO {puts("NO") ; return ;} #define YES {puts("YES") ; return ;} #define endl "\n" #define int long long const int N=1e6+10; int h[N],e[N],ne[N],idx; int l[N],r[N]; void add(int a,int b) { e[idx]=b; ne[idx]=h[a]; h[a]=idx++; } int dfs(int u) { int res=0,sum=0; for(int i=h[u];~i;i=ne[i]) { int j=e[i]; res+=dfs(j); sum+=r[j]; } if(sum<l[u]) res++; else r[u]=min(r[u],sum); return res; } void solve() { int n; cin>>n; idx=0; memset(h,-1,sizeof h); for(int i=2;i<=n;i++) { int x; cin>>x; add(x,i); } for(int i=1;i<=n;i++) cin>>l[i]>>r[i]; cout<<dfs(1)<<endl; } signed main() { int T; cin>>T; while(T--) { solve(); } }

5|0E

核心思路

我们首先假设dist[u]u,但是题目又要我们最小值最大,所以我们可以从dist里面挑选一个大的来作为当前的一条道路,就是说当前人物走了一条相对来说有点大的路,但是我们需要把当前的路还要大的路给堵了。使他走当前这条路。

所以这个题目就需要统计下每个点的入度,然后反向建图。

// Problem: E. Keshi in Search of AmShZ // Contest: Codeforces - Codeforces Round #800 (Div. 2) // URL: https://codeforces.com/contest/1694/problem/E // Memory Limit: 256 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #define _CRT_SECURE_NO_WARNINGS #include<bits/stdc++.h> using namespace std; typedef long long LL; #define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) #define NO {puts("NO") ; return ;} #define YES {puts("YES") ; return ;} #define endl "\n" #define int long long #define x first #define y second typedef pair<int, int> PII; const int N = 1e6 + 10; int h[N], ne[N], idx, e[N]; int dist[N], din[N], st[N]; int n, m; void add(int a, int b) { e[idx] = b; ne[idx] = h[a]; h[a] = idx++; din[b]++; } void dijkstra() { memset(dist, 0x3f, sizeof dist); memset(st, 0, sizeof st); priority_queue<PII, vector<PII>, greater<PII>> q; dist[n] = 0; q.push({ 0,n }); while (q.size()) { auto t = q.top(); q.pop(); int ver = t.y; if (st[ver]) continue; st[ver] = 1; for (int i = h[ver];~i;i = ne[i]) { int j = e[i]; if (dist[j] > dist[ver] + din[j]) { dist[j] = dist[ver] + din[j]; q.push({ dist[j],j }); } din[j]--;//因为我们只需要删除比它大的边。 } } } void solve() { cin >> n >> m; memset(h, -1, sizeof h); while (m--) { int a, b; cin >> a >> b; add(b, a); } dijkstra(); cout << dist[1] << endl; } signed main() { int T=1; while (T--) { solve(); } }

__EOF__

本文作者肖英豪
本文链接https://www.cnblogs.com/xyh-hnust666/p/17073232.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   努力的德华  阅读(30)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示