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 ...
随机推荐
- day9---多线程,线程锁,队列
进程.线程 http://www.ruanyifeng.com/blog/2013/04/processes_and_threads.html 使用threading模块实现多线程编程[综述] Pyt ...
- Linux环境变量配置
/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置./etc/bashrc:为每一个运 ...
- C++多态(一)
面试题目中关于多态的问题不少,例如重载.虚函数(覆盖).多态的概念等等,这里做一个梳理,包含如下内容: 一.多态的定义 (一)定义 能够呈现不同形态的特性或状态. (二)两种多态性 1.编译时的多态性 ...
- FSG报表定义导入
Copying Report Objects From Another Database (FSG Transfer Program) Run the FSG Transfer program to ...
- 骨骼动画的实现(OpenGL实现)
人物模型动画一直是游戏中最重要的组成部分, 因此这里我们研究骨骼动画是如何实现的. 原理 首先模型通常是由多个三角形形成的网格构成, 每个三角形有三个顶点, 因此动画的根本原理就在于不同时间内为每个顶 ...
- I/O requests taking longer than 15 seconds to complete on file I/O瓶颈问题
I/O requests taking longer than 15 seconds to complete on file I/O瓶颈问题 http://mssqlwiki.com/2012/08/ ...
- 【TextBox】重写右键菜单
参考资料 http://bbs.csdn.net/topics/390324356 http://www.cnblogs.com/ycxy/archive/2012/10/09/2716852.htm ...
- FtpDataStream中的隐藏问题
最近在使用FtpWebResponse.GetResponseStream方法时遇上个问题——Stream在未关闭之前就报出了ObjectDisposedException.刚开始十分困惑,因为一直用 ...
- RCP:给GEF编辑器添加拖拽辅助线
当图形边缘碰触时,会产生一条帮助拖拽的辅助线 这里需要三个类: 1.SnapToGeomotry 2.SnapToGuide(非必须) 3.SnapFeedbackPolicy
- Java多线程6:synchronized锁定类方法、volatile关键字及其他
同步静态方法 synchronized还可以应用在静态方法上,如果这么写,则代表的是对当前.java文件对应的Class类加锁.看一下例子,注意一下printC()并不是一个静态方法: public ...