Codeforces Round #277(Div. 2) (A Calculating Function, B OR in Matrix, C Palindrome Transformation)
#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)的更多相关文章
- Codeforces Round #277 (Div. 2) 题解
Codeforces Round #277 (Div. 2) A. Calculating Function time limit per test 1 second memory limit per ...
- 【codeforces】Codeforces Round #277 (Div. 2) 解读
门户:Codeforces Round #277 (Div. 2) 486A. Calculating Function 裸公式= = #include <cstdio> #include ...
- 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation
题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ ...
- Codeforces Round #524 (Div. 2)(前三题题解)
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...
- Codeforces Round #624 (Div. 3)(题解)
Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...
- Codeforces Round #253 (Div. 1) (A, B, C)
Codeforces Round #253 (Div. 1) 题目链接 A:给定一些牌,然后如今要提示一些牌的信息,要求提示最少,使得全部牌能够被分辨出来. 思路:一共2^10种情况,直接暴力枚举,然 ...
- Codeforces Round #277 (Div. 2)---A. Calculating Function (规律)
Calculating Function time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #277 (Div. 2) A. Calculating Function 水题
A. Calculating Function Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/4 ...
- Codeforces Round #277 (Div. 2)---C. Palindrome Transformation (贪心)
Palindrome Transformation time limit per test 1 second memory limit per test 256 megabytes input sta ...
随机推荐
- 结对开发训练(续)(郭林林&胡潇丹)
本次题目:求二维数组最大连续的子数组之和. 通过前两次对问题的分析,这次在拿到题目时,我们首先与前两次题目做对比,尤其与第二次的题目相比较,这是在第二次题目上的扩展,第二次的题目是此次题目的一个特例. ...
- Kernel Functions for Machine Learning Applications
In recent years, Kernel methods have received major attention, particularly due to the increased pop ...
- iOS开发流程总结
本文由社区会员umyueyue分享 以下是会员umyueue总结的iOS开发流程以及学习中的资料分享. 流程:注册.开发.真机测试.发布以及上线. iPhone iOS 4从注册到app上线开发流程 ...
- css长度值与颜色值
颜色值 在网页中的颜色设置是非常重要的,有字体颜色,背景颜色,边框颜色等,设置颜色的方法也有很多种: 1.英文命令颜色 p{color:red;} 2.rgb颜色 p{color:rgb(133,45 ...
- Linux内核--网络栈实现分析(六)--应用层获取数据包(上)
本文分析基于内核Linux 1.2.13 原创作品,转载请标明http://blog.csdn.net/yming0221/article/details/7541907 更多请看专栏,地址http: ...
- 回调函数(callback)
参考维基百科链接: 中文:http://zh.wikipedia.org/wiki/%E5%9B%9E%E8%B0%83%E5%87%BD%E6%95%B0 英文:http://en.wikipedi ...
- 怎样让.bat文件开机自启动
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\R ...
- LINQ LINQ Operators and Lambda Expression - Syntax & Examples
LINQ is a cool feature in C# 3.0. Most of the developers are struggling for the syntax and examples. ...
- 浅论Android网络请求库——android-async-http
在iOS开发中有大名鼎鼎的ASIHttpRequest库,用来处理网络请求操作,今天要介绍的是一个在Android上同样强大的网络请求库android-async-http,目前非常火的应用Insta ...
- mac下android环境搭建笔记(android studio)
本文记录了本人在mac上配置android开发环境的一些过程,为了方便直接选用了官方的IDE– Android Studio .本文包括了android studio的安装.创建第一个hello wo ...