Manthan, Codefest 18 (rated, Div. 1 + Div. 2) C D
#include<bits/stdc++.h>
using namespace std;
using namespace std;
string a,b;
int main(){
int n;
cin>>n;
cin>>a>>b;
,sum=;
;j<n;j++){
if(a[j]!=b[j]) ans++;
}
;j<n-;j++){
if(a[j]==b[j]) continue;
]==]=='){
sum++;
swap(a[j],a[j+]);
}]==]=='){
sum++;
swap(a[j],a[j+]);
}
}
;j<n;j++){
if(a[j]!=b[j]) sum++;
}
cout<<min(sum,ans)<<endl;
;
}
#include<bits/stdc++.h>
using namespace std;
#define maxn 300005
vector<int>q[maxn];
int de[maxn],fa[maxn],ff[maxn];
int a[maxn],vi[maxn],sz[maxn];
void dfs(int u,int f,int d){
de[u]=d;
fa[d]++;
vi[u]=f;
;j<q[u].size();j++){
int v=q[u][j];
if(v==f) continue;
sz[u]++;
dfs(v,u,d+);
}
}
int main(){
memset(de,,sizeof(de));
memset(fa,,sizeof(fa));
memset(vi,,sizeof(vi));
memset(sz,,sizeof(sz));
memset(ff,,sizeof(ff));
int n;
cin>>n;
;j<n;j++){
int u,v;
cin>>u>>v;
q[u].push_back(v);
q[v].push_back(u);
}
;j<=n;j++){
cin>>a[j];
}
dfs(,,);
;
sz[]=;
;j<=n;j++){
int k=de[a[j]];
)) l++;
]!=){
cout<<"No"<<endl;
;
}
if(vi[a[j]]!=a[l]){
cout<<"No"<<endl;
;
}
if(!ff[a[j]]){
ff[a[j]]=;
}else{
cout<<"No"<<endl;
;
}
sz[a[l]]--;
fa[k]--;
}
cout<<"Yes"<<endl;
;
}
Manthan, Codefest 18 (rated, Div. 1 + Div. 2) C D的更多相关文章
- 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T5(思维)
还是dfs? 好像自己写的有锅 过不去 看了题解修改了才过qwq #include <cstdio> #include <algorithm> #include <cst ...
- 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T4(模拟)
随便模拟下就过了qwq 然后忘了特判WA了QwQ #include <cstdio> #include <algorithm> #include <cstring> ...
- 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T3(贪心)
是一道水题 虽然看起来像是DP,但其实是贪心 扫一遍就A了 QwQ #include <cstdio> #include <algorithm> #include <cs ...
- 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T2(模拟)
题目要求很简单,做法很粗暴 直接扫一遍即可 注意结果会爆int #include <cstdio> #include <algorithm> #include <cstr ...
- 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T1(找规律)
就是找一下规律 但是奈何昨天晚上脑子抽 推错了一项QwQ 然后重新一想 A掉了QwQ #include <cstdio> #include <algorithm> #inclu ...
- Codeforces Manthan, Codefest 18 (rated, Div. 1 + Div. 2) D,E
D. Valid BFS? time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 【Manthan, Codefest 18 (rated, Div. 1 + Div. 2) C】Equalize
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] Swap操作显然只能对(i-1,i)执行才有用. 不然直接将i翻转以及j翻转 显然比直接交换更优. 那么现在我们就相当于有两种操作. ...
- 【Manthan, Codefest 18 (rated, Div. 1 + Div. 2) B】Reach Median
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 将数组排序一下. 考虑中位数a[mid] 如果a[mid]==s直接输出0 如果a[mid]<s,那么我们把a[mid]改成s ...
- 【Manthan, Codefest 18 (rated, Div. 1 + Div. 2) A】Packets
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 多重背包的二进制优化. 就是将数量x分成接近log2x份 然后这log2x份能组合成1..x内的所有数字. 从而将多重背包转化成01 ...
随机推荐
- JQuery动态修改样式
JQuery动态修改样式 SetStyle(); function SetStyle() { $(".toolbar").remove(); $(".placeholde ...
- C#的修饰符
C#的修饰符 废话少说,直接上总结: 一.在命名空间下: 类:默认修饰符为internal 接口:默认的修饰符为internal 结构体:默认的修饰符为internal 枚举:默认的修饰符为inter ...
- Oracle调优总结
Oracle调优总结(经典实践 重要) https://blog.csdn.net/dtjiawenwang88/article/details/74892245 https://www.cnblog ...
- html 引入页面公共部分(header、footer)
html引入页面的公共部分,比如导航栏啊,页头页脚之类的. 1.将需要引入的公共html部分转换为js文件,这里推荐一个转换工具地址 http://tool.chinaz.com/Tools/Html ...
- null值经过强转会怎样?
null还是null,类型不会改变的,也不会报错!
- js发布订阅模式实现
//可以用于无相关页面或组件的事件.数据传递,减少在onShow中的业务,降低代码耦合 let events = {} /**订阅**/ function on(name, self, callbac ...
- python爬虫之requests的基本使用
简介 Requests是用python语言基于urllib编写的,采用的是Apache2 Licensed开源协议的HTTP库,Requests它会比urllib更加方便,可以节约我们大量的工作. 一 ...
- 常用css样式处理
1:如何设置html的input框的高度和宽度! 用style来设置,<input style="width:111px;height:111px">
- javascript帧动画
前面的话 帧动画就是在“连续的关键帧”中分解动画动作,也就是在时间轴的每帧上逐帧绘制不同的内容,使其连续播放而成的动画.由于是一帧一帧的画,所以帧动画具有非常大的灵活性,几乎可以表现任何想表现的内容. ...
- Nginx 反向代理接收用户包体方式
陶辉91课 如果proxy_request_buffering 设置为on的时候是等待nginx读取完包体后再发送上游服务器 一般依赖于nginx处理能力 client_body_in_file_o ...