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的更多相关文章
随机推荐
- 强化学习读书笔记 - 10 - on-policy控制的近似方法
强化学习读书笔记 - 10 - on-policy控制的近似方法 学习笔记: Reinforcement Learning: An Introduction, Richard S. Sutton an ...
- 集群服务器、负载均衡和session共享,C#的static变量
集群服务器:是指由两台以上服务器共同组成的服务器,目的是为了提高性能. 负载均衡:是基于集群服务器实现的,作用是当A服务器访问数达到一定上限时,接下来客户端的请求会自动分配给B服务器,目的是减少服务器 ...
- JSP整理
JSP全称Java Server Pages,是一种动态网页开发技术.它使用JSP标签在HTML网页中插入Java代码.标签通常以<%开头以%>结束. JSP是一种Java servlet ...
- CsvHelper文档-6类型转换
CsvHelper文档-6类型转换 CsvHelper使用类型转换器来转换string到对象,或者对象到string: ITypeConverter 类型转换器的结构,必须实现: public int ...
- Nginx特性验证-反向代理/负载均衡/页面缓存/URL重定向
原文发表于cu:2016-08-25 参考文档: Nginx 反向代理.负载均衡.页面缓存.URL重写等:http://freeloda.blog.51cto.com/2033581/1288553 ...
- kubernetes nfs-client-provisioner外部存储控制器
介绍: nfs-client-provisione是一个专门用于NFS外部目录挂载的控制器,当多个副本创建时,他们的命名方式如下: pv provisioned as ${namespace}-${p ...
- KETTLE元数据表
表名 说明 R_CLUSTER R_CLUSTER_SLAVE R_CONDITION R_DATABASE 数据库连接信息 R_DATABASE_ATTRIBUTE 数据库属性 R_DATABASE ...
- 王者荣耀交流协会第二次Scrum立会
会议时间:2017年10月21号 17:00-17:22,时长22分钟. 会议地点:首尔名家里面的大桌子(PS:感谢组长大大请我们吃饭~)立会内容:每位同学汇报了今日工作(高远博与王超同学在今日有 ...
- 1.12Linux下软件安装(学习过程)
实验介绍 介绍 Ubuntu 下软件安装的几种方式,及 apt,dpkg 工具的使用. 一.Linux 上的软件安装 通常 Linux 上的软件安装主要有三种方式: 在线安装 从磁盘安装deb软件包 ...
- c# dictionnary根据value查找对应的key
属性方法中并没有包含此功能,因此需要自己自定义一个方法: string regionName = ""; if (ControlForm.swichLanguage.Contain ...