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 ...
随机推荐
- C# Note5:使用相对路径读取文件
一.C#中使用相对路径读取配置文件 一般Solution的目录结构如下图所示: (如过看不到某些文件,可以点击 “显示所有文件” 图标) 方法一:由于生成的exe文件在bin\debug目录下,可以使 ...
- Python 基础之----网络编程
阅读目录 一 客户端/服务端架构 二 osi七层 三 socket层 四 socket是什么 五 套接字发展史及分类 六 套接字工作流程 七 基于TCP的套接字 八 基于UDP的套接字 九 粘包现象 ...
- 【gedit】 显示行号
打开gedit文本编辑器->Edit(编辑)->preferences(预设)->view(视图)->在Display line numbers前打勾->close
- DAY04、流程控制if、while、for
一.if 判断 语法一: if 条件: # 以下是上一条if 的子代码块 print(子代码1) print(子代码2) print(子代码3) 示例: # 路边飘过一个生物,要不要表白? sex = ...
- $mount(“#app”)手动挂载
没有el属性时,证明vue还没绑定到特定的dom上,需要延迟加载,则使用.$mount("")进行手动挂载 https://blog.csdn.net/longzhoufeng/a ...
- vue開發環境搭建
npm(node package manager),nodejs的包管理器,用於nodejs插件的安裝.卸載和管理依賴. 安裝npm: 檢查npm是否安裝成功及版本:npm -v 卸載npm: 更新n ...
- ArrayList 初学小结!
package good.com; import java.util.ArrayList;//导入 ArrayList 包 调用动态数组! public class ArrayListList { / ...
- word2vec训练&IC分词(待)
参考http://www.52nlp.cn/%E4%B8%AD%E8%8B%B1%E6%96%87%E7%BB%B4%E5%9F%BA%E7%99%BE%E7%A7%91%E8%AF%AD%E6%96 ...
- web跨域请求
第一种情况: 1. sina.com=====>baidu.com/xxx.jsp 也就是前面的域名不相同,(url第三根斜杠之前的内容,也就是主机) 2:localhost =====> ...
- react双向事件的绑定
双向绑定有三步,第一步,触发onChange事件,第二步,拿到input里的值,第三步,使用setState将拿到的值传回到state中. 如何拿到input里的值,可以有两种方法,第一种方法是参数e ...