题目传送门

 /*
贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了
*/
/************************************************
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的更多相关文章

  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. 【BZOJ2527】Meteors(整体二分)

    题意: Byteotian Interstellar Union有N个成员国.现在它发现了一颗新的星球,这颗星球的轨道被分为M份(第M份和第1份相邻),第i份上有第Ai个国家的太空站. 这个星球经常会 ...

  2. 可持久化KMP

    一开始有一空串,n次操作,每次在串末尾加入一个字符问最小循环节.要求在线与可持久化. 如果只是在线的话那是很简单的,答案是!!$i-fail[i]$,其中$fail[i]$是KMP中的失配函数. 但如 ...

  3. [bzoj3630][JLOI2014]镜面通道_计算几何_网络流_最小割

    镜面通道 bzoj-3630 JLOI-2014 题目大意:题目链接. 注释:略. 想法: 我们发现,只要上下界没有被完全封死,我们就一定有一条合法的光路. 所以只需要将上界和下界拆开即可. 拆点,把 ...

  4. Rooks-LightOj1005(规律)

    A rook is a piece used in the game of chess which is played on a board of square grids. A rook can o ...

  5. Remove Duplicates from Sorted List (链表)

    Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...

  6. Restful 级别划分以及HATEOAS是什么?

    Restful简介 Rest是一种软件架构风格.设计风格,而不是标准,只是提供了一组设计原则和约束条件.它主要用于客户端和服务器交互类的软件.基于这个风格设计的软件可以更简洁,更有层次,更易于实现缓存 ...

  7. Ubuntu16.04安装deb文件时提示:此软件来自第三方且可能包含非自由组件

    解决方式: 1.在Ubuntu软件中心安装GDebi. 2.安装好之后,选择这个要安装的deb文件右键,打开方式选择GDebi,然后输入管理员密码等待安装,期间如果不行需要重试几次. 3.另外的方法, ...

  8. swift container server 莫名stuck

    openstack swift container server的进程经常莫名其妙进入 D Ds等状态 记录一下这个时候 storage.error的log 便于分析 一种情形是下面这种log Jun ...

  9. 卸载MySQL 5.0

    昨天在Navicat for mysql中导入一个脚本,执行.出现乱码. 考虑到可能是版本号问题,就想卸载了又一次安装MYSQL,这一卸载倒是出了问题.导致安装的时候安装不上. 后来无意发现是卸载的时 ...

  10. 【block第四篇】实现

    -------------------------------------------欢迎查看block连载博客[专栏]--------------------------------------[b ...