Codeforces edu 7 D. Optimal Number Permutation 构造
来源:互联网 发布:淘宝账号登录不了 编辑:程序博客网 时间:2024/06/05 22:36
题目
题目链接:http://codeforces.com/contest/622/problem/D
题目来源:Educational Codeforces Round 7
简要题意:令一个和式取到最小。
题解
首先可以暴力一下,可以发现都能达到
0 为结果。然后可以发现这样每个数所需的距离是固定的。
将数按照奇数和偶数放到两段中,就能构造出来,其中最后一个不放入,最后塞到空位中。
很容易发现这样一定能够构造出一个解来,挺不错的构造想法题。
代码
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <cstring>#include <stack>#include <queue>#include <string>#include <vector>#include <set>#include <map>#define pb push_back#define mp make_pair#define all(x) (x).begin(),(x).end()#define sz(x) ((int)(x).size())#define fi first#define se secondusing namespace std;typedef long long LL;typedef vector<int> VI;typedef pair<int,int> PII;LL powmod(LL a,LL b, LL MOD) {LL res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}// headconst int N = 5E5+5;int a[N*2];int main(){ int n; while (scanf("%d", &n) == 1) { int l = 1, r = n; for (int i = 1; i < n; i += 2) { a[l++] = a[r--] = i; } l = n+1, r = 2*n-1; for (int i = 2; i < n; i += 2) { a[l++] = a[r--] = i; } int lim = 2*n; for (int i = 1; i <= lim; i++) { if (!a[i]) a[i] = n; printf("%d%c", a[i], i==lim ? '\n' : ' '); } memset(a, 0, sizeof a); } return 0;}
0 0
- Codeforces edu 7 D. Optimal Number Permutation 构造
- codeforces edu round7 D Optimal Number Permutation构造
- Educational Codeforces Round 7 D. Optimal Number Permutation(构造)
- Codeforces 622D Optimal Number Permutation(构造)
- CodeForces 622D Optimal Number Permutation(构造)
- CodeForces 622 D.Optimal Number Permutation(构造)
- Codeforces 622D Optimal Number Permutation【贪心+构造】
- D. Optimal Number Permutation(构造)
- Educational Codeforces Round 7--D. Optimal Number Permutation
- Educational Codeforces Round 7-D. Optimal Number Permutation
- Codeforces 622D Optimal Number Permutation 【贪心】
- codeforces 622D Optimal Number Permutation 思维
- Optimal Number Permutation CodeForces
- cf#ecr7-D - Optimal Number Permutation-构造+脑洞
- codeforces_622D. Optimal Number Permutation(构造)
- codeforces622D Optimal Number Permutation
- CF EDU #8 D - Magic Number
- 【构造】CodeForces 389D
- WEB架构师成长之路之一-走正确的路
- poj 3666 Making the Grade (有序序列,离散化dp)
- FilterDispatcher已被标注为过时解决办法 >>> FilterDispatcher <<< is deprecated!
- WEB架构师成长之路之二-大牛的法宝
- Notepad++自动格式化Java代码
- Codeforces edu 7 D. Optimal Number Permutation 构造
- Java内存模型
- 例题6-11 UVa297 Quadtrees(四分树)
- uva11988数组模拟单向链表
- 进程状态_笔记
- 结合Matrix实现ZoomImageView,包括双击缩放,多点缩放。
- MySql数据库运维 学习日记(一)
- Java中怎么简单的使用正则表达式?
- 文章标题