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的更多相关文章
随机推荐
- 一个非常好用的PHP数组函数
array_column 该函数非常有用,在PHP 5.5中可直接调用. 有如下二维数组,如要抽取每个子数组中的特定项. <?php // Array representing a possib ...
- python基础数据类型补充
python_day_7 一. 今日主要内容: 1. 补充基础数据类型的相关知识点 str. join() 把列表变成字符串 列表不能再循环的时候删除. 因为索引会跟着改变 字典也不能直接循环删除.把 ...
- Qt-QMl-自定义自己想要的TabView
上效果图 上实现源码,这里的代码都是来自Qt官方源码修改其中某一行内容 /* 作者:张建伟 时间:2018年4月8日 简述:自定义TabView,主要实现Tab和实现内容重叠,不在占用独立空间 该文件 ...
- 自动化运维工具saltstack03 -- 之SaltStack的数据系统
SaltStack数据系统 saltstack有两种数据系统:grains与pillar 1.SaltStack数据系统之grains grains可以收集minion端的静态数据(即机器启动时收集一 ...
- Java如何调用shell脚本的
有些时候会碰到这样的场景:java的功能里面要嵌入一个功能点,这个功能是通过是shell脚本实现的.这种时候就需要Java对脚本调用的支持了. 测试环境 Ubuntu16.04 i3-6100,12G ...
- linux ——使用find如何快速替换所有相同参数
在生成环境上有时候需要大规模修改某一配置里的参数,但是该参数存在多个地方,比如IP地址 端口 项目名等,特别是项目名称混乱想统一 find /项目地址 -type f |xargs grep &qu ...
- [T-ARA][너 때문에 미쳐][因为你而疯了]
歌词来源:http://music.163.com/#/song?id=5402880 作曲 : 赵英秀/김태현 [作曲 : 赵英秀/k/gim-Tae-hyeon] 作词 : 辉星 [作词 : 辉星 ...
- react native中props的使用
react native中props的使用 一.props的使用 1:父组件传递的方式 在子组件中可以用this.props访问到父组件传递的值 <View> <Text> { ...
- 吴恩达机器学习笔记——正规方程(Normal Equation)
问题描述:m examples : (x(1),y(1)), (x(2),y(2)),..., (x(m),y(m)) and n features; 计算方法:θ = (XTX)-1XTy; 计算过 ...
- “我爱淘”第二冲刺阶段Scrum站立会议8
完成任务: 完成学院分类的点击查看书籍功能,可以点击书的条目查看书的详细信息.完善界面显示,实现购买功能,优化提示,购买后就将该书从数据库中删去. 计划任务: 将书的详细信息进行完善,并且可以点击收藏 ...