codeforces 622C. Optimal Number Permutation 构造
假设始终可以找到一种状态使得值为0, 那么两个1之间需要隔n-2个数, 两个2之间需要隔n-3个数, 两个3之间隔n-4个数。 我们发现两个三可以放到两个1之间, 同理两个5放到两个3之间....这样就构造好了。
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
int a[];
int main()
{
int n;
cin>>n;
int l = , r = n, cnt = ;
while(r>l) {
a[l++] = cnt, a[r--] = cnt;
cnt+=;
}
l = n+, r = l+n-, cnt = ;
while(r>l) {
a[l++] = cnt, a[r--] = cnt;
cnt+=;
}
for(int i = ; i<=*n; i++) {
if(a[i])
printf("%d ", a[i]);
else
printf("%d ", n);
}
return ;
}
codeforces 622C. Optimal Number Permutation 构造的更多相关文章
- Educational Codeforces Round 7 D. Optimal Number Permutation 构造题
D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...
- CodeForces 622D Optimal Number Permutation
是一个简单构造题. 请观察公式: 绝对值里面的就是 |di-(n-i)|,即di与(n-i)的差值的绝对值. 事实上,对于任何n,我们都可以构造出来每一个i的di与(n-i)的差值为0. 换句话说,就 ...
- codeforces 622D D. Optimal Number Permutation(找规律)
D. Optimal Number Permutation time limit per test 1 second memory limit per test 256 megabytes input ...
- Codeforces 55D Beautiful Number
Codeforces 55D Beautiful Number a positive integer number is beautiful if and only if it is divisibl ...
- [Codeforces 1214A]Optimal Currency Exchange(贪心)
[Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...
- Codeforces Round #275 (Div. 1)A. Diverse Permutation 构造
Codeforces Round #275 (Div. 1)A. Diverse Permutation Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 ht ...
- Codeforces Round #309 (Div. 1) B. Kyoya and Permutation 构造
B. Kyoya and Permutation Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...
- Codeforces 804E The same permutation(构造)
[题目链接] http://codeforces.com/contest/804/problem/E [题目大意] 给出一个1到n的排列,问每两个位置都进行一次交换最终排列不变是否可能, 如果可能输出 ...
- Codeforces Round #350 (Div. 2) F. Restore a Number 模拟构造题
F. Restore a Number Vasya decided to pass a very large integer n to Kate. First, he wrote that num ...
随机推荐
- 解决Android中TextView首行缩进的问题
方式一:(推荐) setText("\u3000\u3000"+xxxxx); 方式二:这种方式不同分辨率会有问题 setText(""+xxxxx); 半角: ...
- 揭密: M2和高房价到底谁推高了谁?
近期,著名经济学家吴敬链向新华网等媒体表示:房价高的根本原本就是货币超发.近期十年来我国M2增长率(广义货币增长率)太快."钱太多了,有些人要保值就要投资买房,又因货币非常多购买力非常强.就 ...
- Unity3D-第一视角射击游戏
一.新建关卡 File,Save Scene,File,New Scene,File,Save Scene as... ,Level02.unity 1.建立场景 从Assets中拖放场景模型到Hie ...
- Spoken English
The Business lunch 9.商务午餐怎样开场?[0731] Is this your first time in shanghai? 10.怎样询问对方的感受?[0801] How do ...
- HTML之学习笔记(四)格式化标签和特殊字符
html常用的格式化标签使用如下 <html> <head> <title></title> </head> <body > & ...
- SQL学习之学会使用子查询
1.SELECT语句是SQL的查询.我之前的随笔中所用的SELECT语句都是简单的查询,即从单个数据库表中检索数据的单条SELECT语句. 查询:任何SQL语句都是查询,但此术语一般指SELECT语句 ...
- 【译】html5游戏入门
[译]html5游戏入门 原文链接 简介 如果你想用canvas做个游戏,那么来对地方了. 但是但是你至少知道javascript怎么拼写(╯‵□′)╯︵┻━┻ 既然没问题,那先来玩一下或者下载 创建 ...
- MYSQL知识点
1.MYSQL为了可移植性,使用"--"做为注释,使用"/*!*/"表示可执行的注释.
- MyEclipse 2013 导入MyEclipse 9.0的EJB项目时,需要注意
点击“next”按钮,出现下面的对话框: 再点击“next”按钮,出现下面的对话框:
- jquery ajax 在ie7不能正常使用
jquery ajax结构不规范到时再ie8以下的用户不能正常使用.比如[1,2,].{1,2,},结构内部的最后不能有“,”.