#include<iostream>
#include<cstring>
#include<cstdio>
/*
题意:计算f(n) = -1 + 2 -3 +4.....+(-1)^n *n的值
思路:偶数和 - 奇数和(或者用等差数列计算化简得到结果)
*/
#include<algorithm>
#define N 10000
using namespace std; int main(){
long long n;
cin>>n;
if(n%==) cout<<n/<<endl;
else cout<<(n-)/ - n<<endl;
return ;
} /*
题意:给定B矩阵,判定能否通过A矩阵得到,如果能,打印出这样的A矩阵
Bij = Ai1||Ai2....||Ain || A1j || A2j .....|| Amj
思路:如果Bij == 0, 那么A矩阵的第i行和第j列的值都为0;
然后检查Bij == 1的时候,那么A矩阵的第i行元素和第j列元素至少要一个1!
*/
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define N 105
using namespace std; int a[N][N];
int b[N][N];
int row[N], col[N];
int main(){
int n, m;
cin>>n>>m;
for(int i=; i<=; ++i)
for(int j=; j<=; ++j)
a[i][j] = ;
bool flag = true;
for(int i=; i<=n; ++i)
for(int j=; j<=m; ++j){
cin>>b[i][j];
if(b[i][j] == ){
for(int k=; k<=m; ++k)
a[i][k] = ;
for(int k=; k<=n; ++k)
a[k][j] = ;
}
}
for(int i=; flag && i<=n; ++i)
for(int j=; flag&& j<=m; ++j)
if(b[i][j] == ){
int k, h;
for(k=; k<=m; ++k)
if(a[i][k]==) break;
for(h=; h<=n; ++h)
if(a[h][j] == ) break;
if(k>m && h>n) flag = false;
}
if(flag){
cout<<"YES"<<endl;
for(int i=; i<=n; ++i){
cout<<a[i][];
for(int j=; j<=m; ++j)
cout<<" "<<a[i][j];
cout<<endl;
}
}
else cout<<"NO"<<endl;
return ;
} /*
题意:从字符串的某一个位置开始,执行向左,向右的操作到达某一个字符的位置,
通过向上,向下来完成字符的转换,知道字符串变成一个回文串为止! 思路:贪心,在一半的区间完成这些操作一定是最少的(回文串是对称的,所以我们只考虑
一半的区间是对的),并且最多转一次弯儿!
*/
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define N 100005
using namespace std;
char str[N];
int num;
int main(){
int n, p;
cin>>n>>p;
cin>>str+;
int len = n;
if(p>len/) p = len-p+;
int lx = N, rx = -;
for(int i=; i<=len/; ++i)//找到个需要更改字符区间
if(str[i] != str[len-i+]){
num += min(abs(str[i]-str[len-i+]), 'z'-max(str[i], str[len-i+])+(min(str[i], str[len-i+])-'a')+);
if(lx > i) lx=i;
if(rx < i) rx=i;
} if(lx != N){
if(lx<=p && rx>=p){
int d1 = abs(rx-p);
int d2 = abs(lx-p);
if(d1>d2) num+=*d2+d1;
else num+=*d1+d2;
}
else if(rx<=p) num+=p-lx;
else if(lx>=p) num+=rx-p;
cout<<num<<endl;
} else cout<<<<endl;
return ;
}

Codeforces Round #277(Div. 2) (A Calculating Function, B OR in Matrix, C Palindrome Transformation)的更多相关文章

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

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

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

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

  3. 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation

    题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ ...

  4. Codeforces Round #524 (Div. 2)(前三题题解)

    这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...

  5. Codeforces Round #624 (Div. 3)(题解)

    Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...

  6. Codeforces Round #253 (Div. 1) (A, B, C)

    Codeforces Round #253 (Div. 1) 题目链接 A:给定一些牌,然后如今要提示一些牌的信息,要求提示最少,使得全部牌能够被分辨出来. 思路:一共2^10种情况,直接暴力枚举,然 ...

  7. Codeforces Round #277 (Div. 2)---A. Calculating Function (规律)

    Calculating Function time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. Codeforces Round #277 (Div. 2) A. Calculating Function 水题

    A. Calculating Function Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/4 ...

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

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

随机推荐

  1. 虚拟机安装Ubuntu到U盘

    这篇经验中特指系统安装到U盘,系统在U盘上,不是双系统,不会改变源系统的设置.只需在启动的时候选择启动路径,就可以从U盘启动你的系统.本文仅仅Ubuntu系统,举一反三可以按照此方法安装各种各样的系统 ...

  2. Connecting sql server2008 through C#

    本实例只在于将通过ASP.NET上的控件(如button.textbox等)结合C#中类的应用,将自己需要的数据存入当地的SQL SERVER数据库中 首先我们在项目中需要建立一个ASP.NET We ...

  3. blog搬迁

    因为一些个人原因,2年后继续写blog,但是blog搬到github上!具体的地址为: http://www.94geek.com 内容以linux的c开发,分布式存储和分布式计算,还有架构为主.

  4. 写在分类之首-----to do list!

    1.增强学习 http://www.wildml.com/2016/10/learning-reinforcement-learning/ 2.RNN 别人的博客目录: 1.学些增强学习(通过代码,练 ...

  5. CentOs笔记

    系统 CentOs7,最小安装,使用 Ext4,/ ,/boot,/swap 使用标准分区,另一个分区做为数据分区,使用 LVM. 更新: http://mirrors.163.com/.help/c ...

  6. STC12C5A60S2笔记6(中断)

    1. 基本特性 1) 中断源 STC12C5A60S2共有十个中断源,每个中断源可设置4类优先级:当相同优先级下各中断优先级由高到低依次如下: 1.1)INT0(外部中断0) 中断向量地址 0003H ...

  7. 谈谈javascript语法里一些难点问题(一)

    1)    引子 前不久我建立的技术群里一位MM问了一个这样的问题,她贴出的代码如下所示: var a = 1; function hehe() { window.alert(a); var a = ...

  8. [ACM_动态规划] 最长上升子序列(LIS)

    问题描述:给n个数,找出最长子序列并输出 问题分析:本题是DAG(有向无环图)最长路问题,设d[i]为以i结尾的最长链的长度,则状态转移方程为:d[i]=max{0,d[j]|j<i & ...

  9. .NET Framework中重点类型的继承关系

    继承关系 Object ├─Array │ └─T[] ├─ArrayList ├─List<T> └─String 集合类型的接口 下图展示了集合类型的各种接口的相互关系.注意,下图中所 ...

  10. 初识canvas,使用canvas做一个百分比加载进度的动画

    canvas作为H5中重要的新增特性,使开发者可以用它来创作各种令人惊叹的作品.先来看一下浏览器对canvas的支持情况. <canvas> 标签定义图形,比如图表和其他图像,我们使用脚本 ...