Codeforces710
【未完待续】
A
The only king stands on the standard chess board. You are given his position in format "cd", where c is the column from 'a' to 'h' and dis the row from '1' to '8'. Find the number of moves permitted for the king.
King moves from the position e4
The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'.
Print the only integer x — the number of moves permitted for the king.
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#define il inline
#define re register
using namespace std;
string a;
int main(){
cin>>a;
if(a[]=='a'||a[]=='h'){
if(a[]==''||a[]=='')
cout<<"";
else cout<<"";
}
else{
if(a[]==''||a[]=='')
cout<<"";
else cout<<"";
}
return ;
}
B
You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal.
The first line contains integer n (1 ≤ n ≤ 3·10^5) — the number of points on the line.
The second line contains n integers xi ( - 10^9 ≤ xi ≤ 10^9) — the coordinates of the given n points.
Print the only integer x — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer.
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#define il inline
#define re register
using namespace std;
int n,a[];
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
sort(a+,a+n+);
if(n&){
cout<<a[n/+];
}
else{
cout<<a[n/];
}
return ;
}
C
Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd.
The only line contains odd integer n (1 ≤ n ≤ 49).
Print n lines with n integers. All the integers should be different and from 1 to n2. The sum in each row, column and both main diagonals should be odd.
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#define il inline
#define re register
using namespace std;
int x=,y,cnt=,n,a[][];
int main(){
cin>>n;y=n/+;
while(cnt<=n*n){
a[x][y]=(cnt++);
if(x==){
if(y==n){
x=;y=n;
}
else{
x=n;y++;
}
}
else if(y==n){
x--;y=;
}
else{
if(a[x-][y+]>){
x++;
}
else{
x--;y++;
}
}
}
for(int i=;i<=n;i++){
for(int j=;j<=n;j++)
cout<<a[i][j]<<" ";
cout<<endl;
}
return ;
}
E
zscoder wants to generate an input file for some programming competition problem.
His input is a string consisting of n letters 'a'. He is too lazy to write a generator so he will manually generate the input in a text editor.
Initially, the text editor is empty. It takes him x seconds to insert or delete a letter 'a' from the text file and y seconds to copy the contents of the entire text file, and duplicate it.
zscoder wants to find the minimum amount of time needed for him to create the input file of exactly n letters 'a'. Help him to determine the amount of time needed to generate the input.
The only line contains three integers n, x and y (1 ≤ n ≤ 10^7, 1 ≤ x, y ≤ 10^9) — the number of letters 'a' in the input file and the parameters from the problem statement.
Print the only integer t — the minimum amount of time needed to generate the input file.
可以花费x的代价使得一个数加一或者减一,或者y的代价使得他乘2,问达到n需要多少的代价
这道题嘛,非常巧妙,看dp方程就ok了,主要是利用了减一之前必须乘2的性质【废话】
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#define il inline
#define re register
using namespace std;
typedef long long ll;
ll f[];
int n,x,y;
int main(){
scanf("%d%d%d",&n,&x,&y);
for(int i=;i<=n;i++){
f[i]=min(f[i-]+x,f[(i+)>>]+y+x*(i&));
}
printf("%I64d",f[n]);
return ;
}
Codeforces710的更多相关文章
随机推荐
- bzoj1901&zoj2112&cogs257 Dynamic Rankings(动态排名系统)
			
bzoj1901&zoj2112&cogs257 Dynamic Rankings(动态排名系统) cogs zoj bzoj-权限 题解 bzoj和zoj都是骗访问量的233,我没有 ...
 - WebGL射线拾取模型——八叉树优化
			
经过前面2篇WebGL射线拾取模型的文章,相信大家对射线和模型面片相交的原理已经有所了解,那么今天我们再深入探究关于射线拾取的一个问题,那就是遍历场景中的所有与射线相交的模型的优化问题.首先我们来复习 ...
 - SQL Server变量杂谈
			
学习SQL的过程有进步的话还是一件很美妙的事情的 在第一家公司虽然只呆了两年,但是感觉是我进步最快的两年.那时候工作和生活都挺充实的,每天都有一点点的收获和付出,其中最大的收获莫过于掌握一些核心技能. ...
 - Memcached&PHP-Memcache安装配置
			
参考文档: memcache官网:https://memcached.org/ 参考:http://www.runoob.com/memcached/memcached-install.html 参考 ...
 - 洛谷【P1854】花店橱窗布置
			
https://www.luogu.org/problemnew/show/P1854 题目描述 某花店现有编号由 1 到 F 的 F 束花, 每一束花的品种都不一样. 编号由 1 到 V 的 V 个 ...
 - [python] Queue.Queue vs. collections.deque
			
https://stackoverflow.com/questions/717148/queue-queue-vs-collections-deque/717199#717199 Queue,Queu ...
 - 原生开发小程序 和 wepy 、 mpvue 对比
			
1.三者的开发文档以及介绍: 原生开发小程序文档:点此进入 wepy 开发文档:点此进入 mpvue 开发文档:点此进入 2.三者的简单对比: 以下用一张图来简单概括三者的区别: 小程序支持的是 WX ...
 - [笔记] centos6.6编译安装httpd2.4.10
			
系统安装包是CentOS-6.6-x86_64-minimal.iso 查看一下uname信息 [root@localhost ~]# uname -a Linux localhost.localdo ...
 - ES6的新特性(3)——变量的解构赋值
			
变量的解构赋值 数组的解构赋值 基本用法 ES6 允许按照一定模式,从数组和对象中提取值,对变量进行赋值,这被称为解构(Destructuring). let a = 1; let b = 2; le ...
 - Factorials 阶乘(思维)
			
Description N 的阶乘写作N!表示小于等于N的所有正整数的乘积.阶乘会很快的变大,如13!就必须用32位整数类型来存储,70!即使用浮点数也存不下了.你的任务是 找到阶乘最后面的非零位.举 ...