Codeforces 482 - Diverse Permutation 构造题
这是一道蛮基础的构造题。
- k +(k - 1) -(k - 2)
1 + k , 1 , k , 2, ...................
\ / \ / \ /
k k-1 k-2
如图所示,先构造第一个数,就是1 + k, 然后接下来每个数字和上个数相差k , k -1 , k -2
这样下来,最后一个数字就是一个中间的数字,过程就是不断向中间逼近。
在k + 1后面的数字,只要升序输出就可以了。
构造题还是不太熟练阿 QAQ
贴代码了:
//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#define ll long long
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
using namespace std;
const int INF = 0x3f3f3f3f; int a[]; int main(){
int i, j, k, t, m, n;
while(EOF != scanf("%d%d",&n,&k)){
if(k == ){
for(i = ; i < n; ++i) printf("%d ",i);
printf("%d\n",n);
continue;
} a[] = + k;
for(i = ; i <= k + ; ++i){
if(i % == )
a[i] = a[i - ] - (k - (i - ));
else
a[i] = a[i - ] + (k - (i - ));
}
int cur = ;
for(i = k + ; i <= n; ++i){
a[i] = k + + cur++;
}
for(i = ; i < n; ++i){
printf("%d ",a[i]);
}
printf("%d\n",a[n]);
}
return ;
}
Codeforces 482 - Diverse Permutation 构造题的更多相关文章
- codeforces C. Diverse Permutation(构造)
题意:1...n 的全排列中 p1, p2, p3....pn中,找到至少有k个 |p1-p2| , |p2-p3|, ...|pn-1 - pn| 互不相同的元素! 思路: 保证相邻的两个数的差值的 ...
- 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 ...
- Educational Codeforces Round 7 D. Optimal Number Permutation 构造题
D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...
- codeforces 483C.Diverse Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/483/C 题目意思:给出 n 和 k,要求输出一个含有 n 个数的排列 p1, p2, ...,pn,使得 ...
- CodeForces 483C Diverse Permutation
Diverse Permutation Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64 ...
- codeforces C. Diverse Permutation
C. Diverse Permutation time limit per test 1 second memory limit per test 256 megabytes input standa ...
- [Codeforces 482A] Diverse Permutation
[题目链接] https://codeforces.com/contest/482/problem/A [算法] 首先构造一个(k + 1)个数的序列 , 满足它们的差为1-k 对于i > k ...
- CodeForces 21C Stripe 2 构造题
题目链接: 题目链接:点击打开链接 #include <cstdio> #include <cstring> #include <algorithm> #inclu ...
- Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)
题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...
随机推荐
- Oracle的大数据类型,BIG DATA TYPE
1.CLOB 字符LOB类型,主要用于存储大型英文字符 2.NCLOB 国际语言字符LOB类型,主要用于存储大型非英文字符 3.BLOB 二进制LOB类型,主要用于存储二进制数据 4.BFILE 二进 ...
- [LeetCode]题解(python):108-Convert Sorted Array to Binary Search Tree
题目来源: https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/ 题意分析: 给出一个排好序的数组,根据这 ...
- [LeetCode]题解(python):095-Unique Binary Search Trees II
题目来源: https://leetcode.com/problems/unique-binary-search-trees-ii/ 题意分析: 给一个整数,返回所有中序遍历是1到n的树. 题目思路: ...
- [LeetCode]题解(python):068-Text Justification
题目来源: https://leetcode.com/problems/text-justification/ 题意分析: 输入一个字符串数组和一个规定长度L.将这个字符串数组的元素尽可能放到长度的L ...
- multi-threaded copy command - robocopy
we can copy files by the powerful robocopy tool, and it allow copy using muliti-threaded as well. As ...
- (Problem 49)Prime permutations
The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual ...
- 使用 Windows Media Center 远程控制
http://windows.microsoft.com/en-us/windows/getting-started-windows-media-center#getting-started-wind ...
- JAVA FILE or I/O学习 - I/O流操作:FileInputStream、FileOutputStream、ObjectInputStream、ObjectOutputStream、InputStreamReader、OutputStreamWriter等
public class IOStreamKnow { /*********************************文件读写方式:字节流**************************** ...
- HDOJ 1043 Eight(A* 搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1043 思路分析: <1> 搜索算法: A*算法, Heuristic函数:曼哈顿距离 &l ...
- java软件工程师成长过程的学习
第一阶段:Java基础,包括java语法,面向对象特征,常见API,集合框架: *第二阶段:java界面编程,包括AWT,事件机制,SWING,这个部分也可以跳过,用的时候再看都能来及: *第三阶段: ...