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 与 C++混编中, 出现error LNK2019: 无法解析的外部符号 "int __cdecl main_(int,char * *)" (?main_@@YAHHPEAPEAD@Z),该符号在函数 main 中被引用
main_ 这个函数的头文件 应该做标准化输出 : extern "C" int main_(int argc, char **argv);
- laravel创建项目
composer create-project --prefer-dist laravel/laravel=5.5.* blog
- 为什么说Java中只有值传递(转载)
出处:https://www.hollischuang.com/archives/2275 关于这个问题,在StackOverflow上也引发过广泛的讨论,看来很多程序员对于这个问题的理解都不尽相同, ...
- [新三板摘牌]国资企业济南华光光电去年终止拟IPO今年摘牌新三板
国资企业济南华光光电去年终止拟IPO今年摘牌新三板 http://blog.sina.com.cn/s/blog_e32cfa770102ycku.html http://stock.qlmoney. ...
- STL中vector、set、list和map
- DAY02、正式介绍python
一.编程语言介绍(***) 1.1.机器语言:直接用计算机能理解的二进制指令编写程序,直接控制硬件 1.2.汇编语言:用英文标签取代二进制指令编写程序,本质也是直接控制硬件 1.3.高级语言:用人类能 ...
- python数据结构与算法第十一天【希尔排序】
1.希尔排序的原理 2.代码实现 def shell_sort(alist): n = len(alist) # 初始步长 gap = n / 2 while gap > 0: # 按步长进行插 ...
- freemarker 设置中文
在web中添加一段代码 <servlet> <servlet-name>freemarker</servlet-name> <servlet-class> ...
- Nginx map模块
L77 Syntax: map string $variable { ... } Default: — Context: http map 指令 curl -H 'aaaa:4444444' -H ' ...
- python基础数据类型—int、bool、字符串的常用方法
1.int int为整型数据,主要用于计算和类型转化(将字符串转为数字) 常用方法 #bit_length()当用二进制表示数字时所用最少位数,如下十进制数12用二进制表示是1100(bin),所以# ...