题目传送门

  1. /*
  2. 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了
  3. */
  4. /************************************************
  5. Author :Running_Time
  6. Created Time :2015-8-3 9:14:02
  7. File Name :B.cpp
  8. *************************************************/
  9. #include <cstdio>
  10. #include <algorithm>
  11. #include <iostream>
  12. #include <sstream>
  13. #include <cstring>
  14. #include <cmath>
  15. #include <string>
  16. #include <vector>
  17. #include <queue>
  18. #include <deque>
  19. #include <stack>
  20. #include <list>
  21. #include <map>
  22. #include <set>
  23. #include <bitset>
  24. #include <cstdlib>
  25. #include <ctime>
  26. using namespace std;
  27. #define lson l, mid, rt << 1
  28. #define rson mid + 1, r, rt << 1 | 1
  29. typedef long long ll;
  30. const int MAXN = 1e5 + ;
  31. const int INF = 0x3f3f3f3f;
  32. const int MOD = 1e9 + ;
  33. char s[MAXN];
  34. int a[MAXN];
  35. int n, p;
  36. int main(void) { //Codeforces Round #277 (Div. 2) C. Palindrome Transformation
  37. scanf ("%d%d", &n, &p); scanf ("%s", s + );
  38. if (p > n / ) p = n - p + ;
  39. int l = n + , r = ; int ans = ;
  40. for (int i=; i<=n/; ++i) {
  41. if (s[i] != s[n-i+]) {
  42. l = min (l, i); r = max (r, i);
  43. ans += min (abs (s[i] - s[n-i+]), - abs (s[i] - s[n-i+]));
  44. }
  45. }
  46. if (ans == ) puts ("");
  47. else {
  48. printf ("%d\n", ans + r - l + min (abs (p - l), abs (r - p)));
  49. }
  50. return ;
  51. }

下面的图片更形象点。。。

贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation的更多相关文章

  1. Codeforces Round #277 (Div. 2)---C. Palindrome Transformation (贪心)

    Palindrome Transformation time limit per test 1 second memory limit per test 256 megabytes input sta ...

  2. Codeforces Round #277 (Div. 2)C.Palindrome Transformation 贪心

    C. Palindrome Transformation     Nam is playing with a string on his computer. The string consists o ...

  3. 【codeforces】Codeforces Round #277 (Div. 2) 解读

    门户:Codeforces Round #277 (Div. 2) 486A. Calculating Function 裸公式= = #include <cstdio> #include ...

  4. Codeforces Round #277 (Div. 2) 题解

    Codeforces Round #277 (Div. 2) A. Calculating Function time limit per test 1 second memory limit per ...

  5. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

  6. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 /* 题意:在n^n的海洋里是否有k块陆地 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 输出完k个L后,之后全部输出S:) 5 10 的例子可以是这样的: LSLS ...

  7. 贪心/数学 Codeforces Round #212 (Div. 2) A. Two Semiknights Meet

    题目传送门 /* 贪心/数学:还以为是BFS,其实x1 + 4 * k = x2, y1 + 4 * l = y2 */ #include <cstdio> #include <al ...

  8. 构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers

    题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少 ...

  9. 构造 Codeforces Round #Pi (Div. 2) B. Berland National Library

    题目传送门 /* 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况 ...

随机推荐

  1. 面向对象:继承(经典类&新式类继承原理、属性查找)、派生

    继承: 继承是指类与类之间的关系,是一种“什么”是“什么”的关系. 继承的功能之一就是用来解决代码重用问题 继承是一种创建新类的方式,在Python中,新建的类可以继承一个或多个父类,父类又可以称为基 ...

  2. elasticsearch 安装ik中文分词

    https://blog.csdn.net/c5113620/article/details/79339541

  3. poj——1469 COURSES

    COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24192   Accepted: 9426 Descript ...

  4. reader dc

    https://get.adobe.com/cn/reader/otherversions/

  5. MongoDB小结13 - find【2个参数】

    第一个参数 MongoDB使用find来进行查询,查询呢,就是返回一个集合中文档的子集,子集合的范围从0个文档到整个集合. find的第一个参数决定了要返回那些文档,其形式也就一个文档,说明了要执行的 ...

  6. 通过ambari安装hadoop集群

    转载:http://www.cnblogs.com/cenyuhai/p/3295635.html 整个过程走完,问题不大,不过有一个事情要注意的是就算创建数据库的,使用localhost会报错,要使 ...

  7. Ubuntu和Win7双系统,ubuntu被删,重新启动之后显示,no such partition

    准备一张windows7的系统安装盘.从光盘启动电脑,在光盘启动完毕之后.按shift+F10,调出cmd命令终端,在终端输入:bootrec/fixmbr OK.重新启动之后就搞定了

  8. 踩坑录-libreoffice fatal error com.sun.start.ucb.Interactive.AugmentedIOException: a folder could not be created

    错误概要: 1.LibreOffice可以正常使用: 2.启动tomcat报错如下: Fatal error The application cannot be started. ][context= ...

  9. Good Zookeeper Tutorial with Java client

    参考: https://stackoverflow.com/questions/33524537/good-zookeeper-tutorial-with-java-client I was tryi ...

  10. [Jest] Automate your migration to Jest using codemods

    Jest is a fantastic testing library, but maybe you've been putting off the switch because migrating ...