#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. c# 根据文件流查看文件真实格式

    今天在做图片注册的功能的时候,测试提出一个问题:将随便一个非图片文件将后缀名改为jpg或其他,上传时应检验图片合法性.然后同事给提供了根据文件流前两个字节判断文件真实格式的思路,代码如下: publi ...

  2. oracle迁移mysql数据库注意

    oracle转mysql修改: . substr() substr( string , 0, 10) 这里测试 必须从 第一位获取 既是 substr(string , 1 , 10)2. to_ch ...

  3. Linux之RPM安装软件

    源码包 (可以看到源代码)      脚本安装包(写好的xsheel一键安装.本质还是源码包和二进制包) 二进制包(RPM包.系统默认包)      包管理系统简单,通过命令就可以安装.卸载     ...

  4. Lucene 查询工具 LQT

    Lucene Query Tool (lqt) 是一个命令行工具用来执行 Lucene 查询并对结果进行格式化输出. 使用方法: 01 $ ./lqt 02 usage: LuceneQueryToo ...

  5. 《C#图解教程》读书笔记之一:C#和.NET框架

    本篇已收录至<C#图解教程>读书笔记目录贴,点击访问该目录可获取更多内容. 一.在.NET之前的编程世界 C#语言是在微软公司的.NET框架上开发程序而设计的,首先作者给大家纠正了一下C# ...

  6. java提高篇(二五)-----HashTable

          在java中与有两个类都提供了一个多种用途的hashTable机制,他们都可以将可以key和value结合起来构成键值对通过put(key,value)方法保存起来,然后通过get(key ...

  7. 我所了解的CSS

    我真的了解css吗? 我这样问自己. 我的思考和这几天的学习来自于看了寒冬winter大神的这篇blog:谈谈面试与面试题 .说实话, 我边看,脑袋里面边翻篇一样的过着我的那点css知识,看完了,整个 ...

  8. [蓝牙] 2、蓝牙BLE协议及架构浅析&&基于广播超时待机说广播事件

    第一章 BLE基本概念了解 一.蓝牙4.0和BLE区别   蓝牙4.0是一种应用非常广泛.基于2.4G射频的低功耗无线通讯技术.蓝牙低功耗(Bluetooth Low Energy ),人们又常称之为 ...

  9. as3 Loader 加载资源后内存泄露无法释放的问题。

    本人用Loader加载外部一个swf.之后unloadAndStop,Flash概要分析发现,内存没有被释放. 网上搜了一大堆文章,要么就是加载bitmapdata之后,自己dispose,要么就是加 ...

  10. How to fix updating ubuntu apt-get problem

    It's my new PC with a new os of ubuntu. every time when I want to install software or update apt-get ...