Educational Codeforces Round 16---部分题解

给你图中一点求出它周围有几个可达的点;
除边界之外都是8个,边界处理一下即可;
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<cctype>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm> using namespace std;
typedef long long LL;
#define N 100100
#define INF 0x3f3f3f3f int main()
{
char a;
int b, ans;
scanf("%c%d", &a, &b);
if(a == 'a' || a == 'h')
{
if(b == || b == )
ans = ;
else
ans = ;
}
else
{
if(b == || b == )
ans = ;
else
ans = ;
}
printf("%d\n", ans);
return ;
}
在坐标抽上给你n个点,选出一个点,使得所有点到这点的距离和最小;
排序输出中间值即可;
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<cctype>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm> using namespace std;
typedef long long LL;
#define N 300100
#define INF 0x3f3f3f3f int a[N]; int main()
{
int n;
scanf("%d", &n);
for(int i=; i<=n; i++)
scanf("%d", &a[i]); sort(a+, a+n+); printf("%d\n", a[(n+)/]);
return ;
}
/*
7
1 2 3 5 8 99 100
6
3 2 1 98 99 100
*/
给你一个奇数n(n<=49)然后把1---n*n这些数填入到n*n的矩阵中,使得每行每列以及两个主对角线的和都为奇数
我们可以发现规律就是在矩阵的中间那个菱形地方填入奇数就能满足条件;
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<cctype>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm> using namespace std;
typedef long long LL;
#define N 300
#define INF 0x3f3f3f3f int main()
{
int n, x = , y = ,a[N][N];
scanf("%d", &n); int half = (n+)/; for(int i=; i<=half; i++)
{
for(int j=half-i+; j<=half+i-; j++)
{
a[i][j] = x;
x += ;
}
}
for(int i=n,m=; i>half; i--,m++)
{
for(int j=half-m+; j<=half+m-; j++)
{
a[i][j] = x;
x += ;
}
}
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
if(a[i][j] == )
{
a[i][j] = y;
y += ;
}
printf("%d%c", a[i][j], j==n?'\n':' ');
}
}
return ;
}
想输入一个长度为 n 字符串,字符串中的字符都是一样的,添加或者删除一个字符各需要x秒,复制并且粘贴共需要y秒,问最少需要多少秒能把n个字符都打出来;
当n为偶数时,n可以由n/2复制得来,也可以由添加n/2个字符得来,所以取两者中的最小值;
当n为奇数是,n要删除一个,或者添加一个字符,所以我们要看两种哪种带来的时间少,谁少取谁;
用递归一层一层的找下去,用find(n)返回到达n所需的最优解;
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;
#define N 2010
#define met(a, b) memset(a, b, sizeof(a))
#define INF 0x3f3f3f3f
#define LINF 10e16
typedef long long LL; LL x, y; LL Find(LL n)
{
if(n == ) return ;
if(n == ) return x;///必须由添加一个字符得来; if(n% == )
{
LL num = Find(n/);
return min(num + x*(n/), num + y);
}
else
{
LL num1 = Find(n-);
LL num2 = Find(n+);
return min(num1, num2) + x;
}
} int main()
{
LL n;
scanf("%I64d %I64d %I64d", &n, &x, &y);
LL ans = Find(n);
printf("%I64d\n", ans);
return ;
}
Educational Codeforces Round 16---部分题解的更多相关文章
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- [Educational Codeforces Round 16]B. Optimal Point on a Line
[Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...
- [Educational Codeforces Round 16]A. King Moves
[Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- Educational Codeforces Round 64 部分题解
Educational Codeforces Round 64 部分题解 不更了不更了 CF1156D 0-1-Tree 有一棵树,边权都是0或1.定义点对\(x,y(x\neq y)\)合法当且仅当 ...
- Educational Codeforces Round 64部分题解
Educational Codeforces Round 64部分题解 A 题目大意:给定三角形(高等于低的等腰),正方形,圆,在满足其高,边长,半径最大(保证在上一个图形的内部)的前提下. 判断交点 ...
- Educational Codeforces Round 63部分题解
Educational Codeforces Round 63 A 题目大意就不写了. 挺简单的,若果字符本来就单调不降,那么就不需要修改 否则找到第一次下降的位置和前面的换就好了. #include ...
- Educational Codeforces Round 16 E. Generate a String dp
题目链接: http://codeforces.com/problemset/problem/710/E E. Generate a String time limit per test 2 seco ...
- Educational Codeforces Round 16 D. Two Arithmetic Progressions (不互质中国剩余定理)
Two Arithmetic Progressions 题目链接: http://codeforces.com/contest/710/problem/D Description You are gi ...
随机推荐
- HDU 1561 (树形DP+背包)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1561 题目大意:从树根开始取点.最多取m个点,问最大价值. 解题思路: cost=1的树形背包. 有 ...
- 【BZOJ】2435: [Noi2011]道路修建(树形dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=2435 我怎么感觉那么水.. 坑的是,dfs会爆...好吧..用bfs.. //upd:我的智商也是醉 ...
- 【SPOJ】10628. Count on a tree(lca+主席树+dfs序)
http://www.spoj.com/problems/COT/ (速度很快,排到了rank6) 这题让我明白了人生T_T 我知道我为什么那么sb了. 调试一早上都在想人生. 唉. 太弱. 太弱. ...
- 我装GitHub的过程
GitHub是老师推荐的没正真的使用过,这次安装也是按提示的,不知对否,且还没使用,只是记录一下自己的过程.我是在线安装的. 1.下载GitHub安装问价,双击开始安装 2.出现的可能是系统相关配置吧 ...
- SQL优化之【类型转换】
DBA的日常工作中SQL优化占大半的时间,通常都是SQL语句性能问题或者schema设计有问题,最近遇到一个类型转换的问题,所以在这里分享一下,废话不多说了,直接建表进行测试. mysql), key ...
- Java判断一个时间是否在另一个时间段内
需求:当时间在凌晨0点至0点5分之间程序不执行. 也就是实现判断当前时间点是否在00:00:00至00:05:00之间 方法: Java代码 : /** * 判断时间是否在时间段内 * * @para ...
- IntelliJ IDEA(社区版)学习记录
一.下载 地址:官网下载地址 二.安装 运行安装程序,一路下一步.注意选择安装路径. 三.基本概念 project:相当于donet下的解决方案 module:相当于donet下的项目工程 四.IDE ...
- Yii源码阅读笔记(十七)
View.php,继承了component,用于渲染视图文件: namespace yii\base; use Yii; use yii\helpers\FileHelper; use yii\wid ...
- BIgInteger类和BigDecimal类的理解
第一部分: 这两个类位于java.math包内,要使用它们必须在类前面引用该包:import java.math.BigInteger;和import java.math.BigDecimal; Bi ...
- PHP5.4安装xhprof扩展[不要去pecl下载]
HP5.3或之前版本可以去pecl(http://pecl.php.net)下载xhprof扩展安装. 但pecl上的版本不支持PHP5.4 可以到github上的xhprof库中下载:https:/ ...