贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation
- /*
- 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了
- */
- /************************************************
- Author :Running_Time
- Created Time :2015-8-3 9:14:02
- File Name :B.cpp
- *************************************************/
- #include <cstdio>
- #include <algorithm>
- #include <iostream>
- #include <sstream>
- #include <cstring>
- #include <cmath>
- #include <string>
- #include <vector>
- #include <queue>
- #include <deque>
- #include <stack>
- #include <list>
- #include <map>
- #include <set>
- #include <bitset>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- #define lson l, mid, rt << 1
- #define rson mid + 1, r, rt << 1 | 1
- typedef long long ll;
- const int MAXN = 1e5 + ;
- const int INF = 0x3f3f3f3f;
- const int MOD = 1e9 + ;
- char s[MAXN];
- int a[MAXN];
- int n, p;
- int main(void) { //Codeforces Round #277 (Div. 2) C. Palindrome Transformation
- scanf ("%d%d", &n, &p); scanf ("%s", s + );
- if (p > n / ) p = n - p + ;
- int l = n + , r = ; int ans = ;
- for (int i=; i<=n/; ++i) {
- if (s[i] != s[n-i+]) {
- l = min (l, i); r = max (r, i);
- ans += min (abs (s[i] - s[n-i+]), - abs (s[i] - s[n-i+]));
- }
- }
- if (ans == ) puts ("");
- else {
- printf ("%d\n", ans + r - l + min (abs (p - l), abs (r - p)));
- }
- return ;
- }
下面的图片更形象点。。。
贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation的更多相关文章
- Codeforces Round #277 (Div. 2)---C. Palindrome Transformation (贪心)
Palindrome Transformation time limit per test 1 second memory limit per test 256 megabytes input sta ...
- Codeforces Round #277 (Div. 2)C.Palindrome Transformation 贪心
C. Palindrome Transformation Nam is playing with a string on his computer. The string consists o ...
- 【codeforces】Codeforces Round #277 (Div. 2) 解读
门户:Codeforces Round #277 (Div. 2) 486A. Calculating Function 裸公式= = #include <cstdio> #include ...
- Codeforces Round #277 (Div. 2) 题解
Codeforces Round #277 (Div. 2) A. Calculating Function time limit per test 1 second memory limit per ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
- 构造 Codeforces Round #302 (Div. 2) B Sea and Islands
题目传送门 /* 题意:在n^n的海洋里是否有k块陆地 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 输出完k个L后,之后全部输出S:) 5 10 的例子可以是这样的: LSLS ...
- 贪心/数学 Codeforces Round #212 (Div. 2) A. Two Semiknights Meet
题目传送门 /* 贪心/数学:还以为是BFS,其实x1 + 4 * k = x2, y1 + 4 * l = y2 */ #include <cstdio> #include <al ...
- 构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers
题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少 ...
- 构造 Codeforces Round #Pi (Div. 2) B. Berland National Library
题目传送门 /* 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况 ...
随机推荐
- 面向对象:继承(经典类&新式类继承原理、属性查找)、派生
继承: 继承是指类与类之间的关系,是一种“什么”是“什么”的关系. 继承的功能之一就是用来解决代码重用问题 继承是一种创建新类的方式,在Python中,新建的类可以继承一个或多个父类,父类又可以称为基 ...
- elasticsearch 安装ik中文分词
https://blog.csdn.net/c5113620/article/details/79339541
- poj——1469 COURSES
COURSES Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24192 Accepted: 9426 Descript ...
- reader dc
https://get.adobe.com/cn/reader/otherversions/
- MongoDB小结13 - find【2个参数】
第一个参数 MongoDB使用find来进行查询,查询呢,就是返回一个集合中文档的子集,子集合的范围从0个文档到整个集合. find的第一个参数决定了要返回那些文档,其形式也就一个文档,说明了要执行的 ...
- 通过ambari安装hadoop集群
转载:http://www.cnblogs.com/cenyuhai/p/3295635.html 整个过程走完,问题不大,不过有一个事情要注意的是就算创建数据库的,使用localhost会报错,要使 ...
- Ubuntu和Win7双系统,ubuntu被删,重新启动之后显示,no such partition
准备一张windows7的系统安装盘.从光盘启动电脑,在光盘启动完毕之后.按shift+F10,调出cmd命令终端,在终端输入:bootrec/fixmbr OK.重新启动之后就搞定了
- 踩坑录-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= ...
- Good Zookeeper Tutorial with Java client
参考: https://stackoverflow.com/questions/33524537/good-zookeeper-tutorial-with-java-client I was tryi ...
- [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 ...