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. PHP中对象是按值传递还是按引用传递?

    1.首先,什么是按值传递和按引用传递? 按值传递就是仅仅把值传递过去,相当于传递的是值的拷贝,而按引用传递传递的是内存的地址. 在 PHP5 中,如果按引用传递,就是将 zval 的地址赋给另一个变量 ...

  2. Azure系列2.1.10 —— CloudBlobClient

    (小弟自学Azure,文中有不正确之处,请路过各位大神指正.) 网上azure的资料较少,尤其是API,全是英文的,中文资料更是少之又少.这次由于公司项目需要使用Azure,所以对Azure的一些学习 ...

  3. [转帖]再次提醒Google Chrome用户应尽快升级浏览器到72.0.3626.121

    再次提醒Google Chrome用户应尽快升级浏览器到72.0.3626.121 转帖地址: https://www.cnbeta.com/articles/tech/825591.htm 国内离线 ...

  4. git遇到的问题 .Git: There is no tracking information for the current branch.

    1.Git: There is no tracking information for the current branch. 在执行git pull的时候,提示当前branch没有跟踪信息: git ...

  5. python爬虫之scrapy文件下载

    我们在写普通脚本的时候,从一个网站拿到一个文件的下载url,然后下载,直接将数据写入文件或者保存下来,但是这个需要我们自己一点一点的写出来,而且反复利用率并不高,为了不重复造轮子,scrapy提供很流 ...

  6. for 循环增强

    package cn.zhou.com; /* * 增强for循环 * * for(int i:arr) * { * System.out.print(i+1+" "); * } ...

  7. MyBatis Generator报错:Cannot instantiate object of type

    [ERROR] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate ( ...

  8. react 入坑笔记(一)

    一些概念: 1.组件:概念等同于 vue 中的组件,字面意思,不过 vue 中组件是以 .vue 结尾,通过 vue-loader 编译成 js,而 react 组件就是 js. 2.jsx:js 语 ...

  9. Nginx用户权限验证管理

    首先需要编译进--with-http_request_model 配置指令:auth_request url | off; #url是指上游服务器地址 context: http/location 备 ...

  10. 基于 vue+vue-router+vuex+axios+koa+koa-router 本地开发全栈项目

    因为毕业设计要做基于Node服务器的项目,所以我就想着用刚学的vue作为前端开发框架,vue作为Vue.js应用程序的状态管理模式+库,axios基于promise用于浏览器和node.js的http ...