C - Equalize

#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;

  ;
}

D - Valid BFS?

#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的更多相关文章

  1. 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T5(思维)

    还是dfs? 好像自己写的有锅 过不去 看了题解修改了才过qwq #include <cstdio> #include <algorithm> #include <cst ...

  2. 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T4(模拟)

    随便模拟下就过了qwq 然后忘了特判WA了QwQ #include <cstdio> #include <algorithm> #include <cstring> ...

  3. 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T3(贪心)

    是一道水题 虽然看起来像是DP,但其实是贪心 扫一遍就A了 QwQ #include <cstdio> #include <algorithm> #include <cs ...

  4. 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T2(模拟)

    题目要求很简单,做法很粗暴 直接扫一遍即可 注意结果会爆int #include <cstdio> #include <algorithm> #include <cstr ...

  5. 题解——CF Manthan, Codefest 18 (rated, Div. 1 + Div. 2) T1(找规律)

    就是找一下规律 但是奈何昨天晚上脑子抽 推错了一项QwQ 然后重新一想 A掉了QwQ #include <cstdio> #include <algorithm> #inclu ...

  6. 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 ...

  7. 【Manthan, Codefest 18 (rated, Div. 1 + Div. 2) C】Equalize

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] Swap操作显然只能对(i-1,i)执行才有用. 不然直接将i翻转以及j翻转 显然比直接交换更优. 那么现在我们就相当于有两种操作. ...

  8. 【Manthan, Codefest 18 (rated, Div. 1 + Div. 2) B】Reach Median

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 将数组排序一下. 考虑中位数a[mid] 如果a[mid]==s直接输出0 如果a[mid]<s,那么我们把a[mid]改成s ...

  9. 【Manthan, Codefest 18 (rated, Div. 1 + Div. 2) A】Packets

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 多重背包的二进制优化. 就是将数量x分成接近log2x份 然后这log2x份能组合成1..x内的所有数字. 从而将多重背包转化成01 ...

随机推荐

  1. js 判断字符串中是否包含某个字符串的方法实例

    String对象的方法 方法一: indexOf()   (推荐) var str = "123"; console.log(str.indexOf("3") ...

  2. mybatis源码分析(四)---------------代理对象的生成

    在mybatis两种开发方式这边文章中,我们提到了Mapper动态代理开发这种方式,现在抛出一个问题:通过sqlSession.getMapper(XXXMapper.class)来获取代理对象的过程 ...

  3. smarTTY总是失败连接的原因

    首先用命令 IP addr 查看是否ip 地址错误  事实证明就是因为我的ip地址发生了变化所以导致连接不上, 不过有一次,我将电脑重启 也是连接上了的.

  4. bootStrap的使用

    1.首先要打开bootstrap的官网 点进去 2你会看到下面这样一个页面里面有很多组件 这里面的代码是实现组件功能的核心代码,还不能直接使用,要引入相关的js css 我们要在起步中下载相关的页面下 ...

  5. js 首次进入弹窗

    今天有个需求,首次进入需要弹窗,然后就在网上找了下,虽然看了很多但是说的都不是我想要的,最后终于到了一个合适的. function get_cookie(Name) { var search = Na ...

  6. WPF设置软件界面背景为MediaElement并播放视频

    在我们的常见的软件界面设计中我们经常会设置软件的背景为SolidColorBrush或者LinerColorBrush.RadialGradientBrush 等一系列的颜色画刷为背景,有时我们也会使 ...

  7. 记一次tomcat7.0版本启动项目失败问题

    测试项目在tomcat7中启动失败,报错如下: @794314bc3 Error during job execution (jobs.Bootstrap) Oops: VerifyError ~ p ...

  8. tomcat 和jboss区别

    参考http://blog.csdn.net/sz_bdqn/article/details/6762175

  9. ubuntu16.04下 搭建 lnmp 环境

    apt-get install nginx apt-get php7.-mysql apt-get install mysql 编辑nginx配置文件 vim /etc/nginx/sites-ena ...

  10. CountDownLatch(三)

    CountDownLatch简介 (1)用于解决什么问题? 在并发编程的场景中,最常见的一个case是某个任务的执行,需要等到多个线程都执行完毕之后才可以进行,CountDownLatch可以很好解决 ...