Codeforces Round #110 (Div. 2)

C. Message

题意

  • 给两个长度不超过2000的字符串\(s,u\),仅由小写字母构成。
  • 找出\(s\)的一个子串\(t\),通过3种操作变换成字符串\(u\):
  1. 在首或尾添加一个字符;
  2. 删除首或尾的一个字符;
  3. 改变某个位置的字符。
  • 求最小的操作步数。

思路

  • 因为删除、插入的代价和修改的代价一样,显然找出和\(u\)长度一样的子串\(t\)可以求得最小代价。
  • 显然\(u\)可以只匹配\(s\)的一个前缀或后缀,可以通过在\(s\)首或尾添加非字母字符。

代码


D. Suspects

题意

  • 有\(N(N \le 10^5)\)个嫌疑人,其中一个是凶手。
  • 每个人会有一个回答(\(+a_i或-a_i\)),分别表示\(i\)认为\(a_i\)是凶手和不是凶手。
  • 已知全部回答中只有\(m\)个回答是真的,其余都是假的。
  • 对于每个回答,判定嫌疑人是否在说谎,输出\(Truth\)或\(Lie\),如果无法判断,则输出\(Not defined\)。

思路

  • 判断一个人是否是凶手:统计认为\(i\)是凶手的数量\(c[i]\),以及认为\(i\)不是凶手的数量\(nc[i]\),则为真的回答数=\[c[i]-nc[i]+\sum_{j=1}^{n}{nc[j]}\]
  • 假定\(i\)是凶手,则\([1, i)\)和\((i, n]\)的人不是凶手。维护\(L\)的最大值,\(R\)的最小值,使得\([1, L)\)和\((R, n]\)的人不是凶手。
  • 当\(a_i\)可能是凶手,也可能不是凶手时,就无法判断嫌疑人的回答是否撒谎。

代码


E. Cipher

题意

  • 给长度不超过100的字符串\(s\)。
  • 有两种操作,每次操作选择一个位置\(p(1 \le p \lt |s|)\):
  1. \(++s_p, --s_{p+1}\)
  2. \(--s_p, ++s_{p+1}\)
  • 经过若干次操作,变成了串\(t\),求不同的串\(t\)的数量。

思路

  • 认真想一下的话,可以发现串的总和是不变的,两种操作想当于把1扔到相邻的位置上。
  • 那么用\(f[i][j]\)表示i个字符组成和为j的方案数即可。

代码

Codeforces Round #110 (Div. 2)的更多相关文章

  1. Codeforces Round #485 (Div. 2) D. Fair

    Codeforces Round #485 (Div. 2) D. Fair 题目连接: http://codeforces.com/contest/987/problem/D Description ...

  2. Codeforces Round #497 (Div. 2)

    Codeforces Round #497 (Div. 2) https://codeforces.com/contest/1008 A #include<bits/stdc++.h> u ...

  3. Codeforces Round #247 (Div. 2) ABC

    Codeforces Round #247 (Div. 2) http://codeforces.com/contest/431  代码均已投放:https://github.com/illuz/Wa ...

  4. Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics)

    A. Even Subset Sum Problem 题意 给出一串数,找到其中的一些数使得他们的和为偶数 题解 水题,找到一个偶数或者两个奇数就好了 代码 #include<iostream& ...

  5. Codeforces Round #620 (Div. 2)

    Codeforces Round #620 (Div. 2) A. Two Rabbits 题意 两只兔子相向而跳,一只一次跳距离a,另一只一次跳距离b,每次同时跳,问是否可能到同一位置 题解 每次跳 ...

  6. Codeforces Round #633 (Div. 2)

    Codeforces Round #633(Div.2) \(A.Filling\ Diamonds\) 答案就是构成的六边形数量+1 //#pragma GCC optimize("O3& ...

  7. Codeforces Round #713 (Div. 3)AB题

    Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...

  8. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  9. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

随机推荐

  1. poj 2536 GopherII(二分图匹配)

    Description The gopher family, having averted the canine threat, must face a new predator. The are n ...

  2. java面试题之ssh

    1.写出你熟悉的开源框架以及各自的作用(项目中为什么使用SSH) 答:框架:hibernate,spring,struts1/struts2. Hibernate主要用于数据持久化:封装了JDBC操作 ...

  3. 【转发】du命令 实现Linux 某个文件夹下的文件按大小排序

    1. df -lh 2. du -s /usr/* | sort -rn这是按字节排序 3. du -sh /usr/* | sort -rn这是按兆(M)来排序 4.选出排在前面的10个du -s ...

  4. 上架app 到app store 的出现: “The IPA is invalid. It does not inlude a Payload directory.”错误处理

    今天打包上传app到app store上遇到的一个错误,在xcode6.2下提示: The IPA is  invalid. It does not inlude a Payload director ...

  5. <二叉树的基本操作(有层次遍历)>

    #include<stdio.h> #include<stdlib.h> #include<string.h> #define num 100 #define OK ...

  6. Core Animation系列之CADisplayLink

    一直以来都想好好学习下CoreAnimation,奈何涉及的东西太多,想要一次性全部搞定时间上不允许,以后会断断续续的补全.最近项目里用到了CADisplayLink,就顺便花点时间看了看. 一.简介 ...

  7. UIControl的使用

    在开发当中,可能很多时候都需要做个点赞的需求,如果用按钮实现,按钮作为一个系统复合控件,外部是一个 View-->UIControl的容器, 内部包含了UILabel和UIImage,以及一些排 ...

  8. IOS(SystemConfiguration)框架中关于测试连接网络状态相关方法

    1. 在SystemConfiguration.famework中提供和联网相关的function, 可用来检查网络连接状态. 2. SC(SystemConfiguration)框架中关于测试连接网 ...

  9. Android.mk中添加宏定义

    在Boardconfig.mk 中添加一个 IS_FLAG := true 由于Boardconfig.mk和各目录的Android.mk是相互关联的 所以我们可以在Android.mk 中添加 一个 ...

  10. 获取本机IP非127.0.0.1

    protected function GetiP()    {    $preg="/\A((([0-9]?[0-9])|(1[0-9]{2})|(2[0-4][0-9])|(25[0-5] ...