Codeforces Round #275 (Div. 1)A. Diverse Permutation (水)

题意:

从1-n的数,让你选择一些数来构造,要求每个相邻的数之间的绝对值之差有k种

题解:

先放好一个1   然后往后面插数字   先满足绝对值不同的  然后全插绝对值为1的,

代码:

#include<stdio.h>

#include<string.h>

int main()

{

int n, k, a[100005], mark[100005];

while(scanf("%d %d", &n, &k) != EOF)

{

memset(a, 0, sizeof(a));

memset(mark, 0, sizeof(mark));

a[0] = 1, mark[1] = 1;

if(k == 1)

{

printf("1");

for(int i = 2; i <= n; i++)

{

printf(" %d", i);

}

printf("\n");

continue;

}

int value = n-1,num = 0, w;

k--;

while(k > 0)

{

if(a[num] - value <= 1 || mark[a[num] - value]) w = a[num] + value;

else w = a[num] - value;

k --;

value --;

a[++num] = w;

mark[w] = 1;

}

int k = num;

if(w + 1 > n || mark[w+1])

{

int date = w-1;

while(num < n-1)

{

a[++num] = date --;

}

}

else

{

int date = w+1;

while(num < n-1)

{

a[++num] = date ++;

}

}

printf("%d", a[0]);

for(int i = 1; i <= num; i++)

{

printf(" %d", a[i]);

}

printf("\n");

}

}

时间: 2024-08-01 13:31:52

Codeforces Round #275 (Div. 1)A. Diverse Permutation (水)的相关文章

Codeforces Round #275 (Div. 1)A. Diverse Permutation 构造

Codeforces Round #275 (Div. 1)A. Diverse Permutation Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/482/problem/A Description Permutation p is an ordered set of integers p1,   p2,   ...,   pn, consisting of n distinct posi

Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)

题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列其中相邻两项差的绝对值的个数(指绝对值不同的个数)为k个.求序列. 思路:1~k+1.构造序列前段,之后直接输出剩下的数.前面的构造可以根据,两项差的绝对值为1~k构造. AC代码: #include <stdio.h> #include <string.h> int ans[200010]; bool vis[100010]; i

Codeforces Round #486 (Div. 3) A. Diverse Team

Codeforces Round #486 (Div. 3) A. Diverse Team 题目连接: http://codeforces.com/contest/988/problem/A Description There are n students in a school class, the rating of the i-th student on Codehorses is ai. You have to form a team consisting of k students

Codeforces Round #275 (Div. 2)

链接:http://codeforces.com/contest/483 A. Counterexample time limit per test 1 second memory limit per test 256 megabytes Your friend has recently learned about coprime numbers. A pair of numbers {a,?b} is called coprime if the maximum number that divi

CF 275(div.1) A Diverse Permutation

Diverse Permutation 题意:一个1~n的无重复整数序列,要求打印其中一种排列,使新序列相邻两项之差的绝对值去重后的个数刚好为k个     (1 <= k < n <= 10^5) 输入:n,k 输出:新序列 思路:想了一下,先考虑k最大和k最小取值时的序列排列情况 1) k最大时:k = n-1  序列:1,n,2,n-1,3,n-2.... 相邻两项绝对值差:n-1,n-2,n-3...1 2) k最小时:k = 1     序列:1,2,3...n | n,n-1,

[Codeforces Round #275 (Div. 2)]B - Friends and Presents

最近一直在做 codeforces ,总觉得已经刷不动 BZOJ 了? ——真是弱喵 你看连 Div.2 的 B 题都要谢谢题解,不是闲就是傻 显然我没那么闲 ╮(╯_╰)╭ 我觉得这题的想法挺妙的~ 大意是你需要分别给 a 和 b cnt1 和 cnt2 个数字 但是 a 不要被 x 整除的数 ,as well as,b 不要被 y 整除的数 然后求需要给的最大数的最小值—— 最值的最值?那不是典型的二分吗? 但是——坑爹的英文题导致我完全没有意识到这一点…… 二分答案 v ,因为 a 不要被

Codeforces Round #275 (Div.1) Solution

好久没做题了,开场Virtual热热身. A 构造,我的方法是,取1,2,3...,k这几个差值,前k+1个数分别是 1, k+1, 2, k, ...., 之后就k+2, k+3, ..., n B 因为题设是与操作.我们按照每一位来,如果有一个限制某位是1,则将那段区间标志1,没有限制的位全部置零即可,然后检验为0的位是否全是1.标志一段区间可以用标记法,检验可以求和看差值. C 我做完之后看了CF tutorial 跟我的做法不同.我的做法比他给的复杂度低一点,不过题解好帅,而且跑出来速度

Codeforces Round #275 (Div. 2) A

题目传送门:http://codeforces.com/contest/483/problem/A 题意分析:在l到r的范围内找三个数,a,b,c . a和b互质,b和c互质,但a和c不是互质. 因为r-l<=50.所以直接暴力枚举三个数就行了. 代码: #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <iostream>

Codeforces Round #275 (Div. 2) B

题目传送门:http://codeforces.com/contest/483/problem/B 题意分析:在1-v的范围内找到一些数分为两个集合,满足第一个集合的元素不能被x整除且个数为cnt1, 第二个集合的元素不能被y整除且个数为cnt2,求最小的v: 二分答案,然后用只满足整除x,只满足整除y和既可整除x又可整除y这三个元素的关系去check一下 代码: #include <cstdio> #include <algorithm> #include <cstring