Codeforces Round #275 (Div. 2) C
题目传送门:http://codeforces.com/contest/483/problem/C
题意分析:题目意思没啥好说的。
去搞排列列举必须TLE。那么就想到构造。 1。n。2。n-1。3。n-2这个样子。
k/2就是须要交换的元素对数,还须要考虑一下k的奇偶去推断没交换的元素是顺序输出还是逆序输出。自己尝试下几个数据就明确了。
代码:
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream> using namespace std; typedef long long LL; int p[100005];
int main()
{
int n,k;
while(cin>>n>>k)
{
for(int i=0; i<n; i++)
{
p[i]=i+1;
}
int flag=0;
int temp=n-1;
int m=k/2;
int x=k;
while(m--)
{
printf("%d ",p[flag]);
printf("%d ",p[temp]);
flag++;
temp--;
}
if(x%2==0)
{
for(int i=temp; i>=flag; i--)
{
printf("%d ",p[i]);
}
}
if(x%2==1)
{
for(int i=flag; i<=temp; i++)
{
printf("%d ",p[i]);
}
}
printf("\n");
}
}
Codeforces Round #275 (Div. 2) C的更多相关文章
- Codeforces Round #275 (Div. 2) C - Diverse Permutation (构造)
题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...
- 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 #275 (Div. 2) C. Diverse Permutation
题目传送门 /* 构造:首先先选好k个不同的值,从1到k,按要求把数字放好,其余的随便放.因为是绝对差值,从n开始一下一上, 这样保证不会超出边界并且以防其余的数相邻绝对值差>k */ /*** ...
- [Codeforces Round #275 (Div. 2)]B - Friends and Presents
最近一直在做 codeforces ,总觉得已经刷不动 BZOJ 了? ——真是弱喵 你看连 Div.2 的 B 题都要谢谢题解,不是闲就是傻 显然我没那么闲 ╮(╯_╰)╭ 我觉得这题的想法挺妙的~ ...
- Codeforces Round #275(Div. 2)-C. Diverse Permutation
http://codeforces.com/contest/483/problem/C C. Diverse Permutation time limit per test 1 second memo ...
- Codeforces Round #275 (Div. 2)-A. Counterexample
http://codeforces.com/contest/483/problem/A A. Counterexample time limit per test 1 second memory li ...
- Codeforces Round #275 Div.1 B Interesting Array --线段树
题意: 构造一个序列,满足m个形如:[l,r,c] 的条件. [l,r,c]表示[l,r]中的元素按位与(&)的和为c. 解法: 线段树维护,sum[rt]表示要满足到现在为止的条件时该子树的 ...
- Codeforces Round #275 (Div. 2)
A. Counterexample 题意:给出l,r,找出使得满足l<a<b<c<r,同时满足a,b的最大公约数为1,b,c的最大公约数为1,且a,b的最大公约数不为1 因为题 ...
- Codeforces Round #275 (Div. 2) 题解
A 题: 说的是在(LR) 之间找出ab互质 bc 互质 ac 不互质的 3个数 数据量小直接暴力 #include <iostream> #include <cstdio> ...
随机推荐
- codeforces-574B
题目连接:http://codeforces.com/contest/574/problem/B B. Bear and Three Musketeers time limit per test 2 ...
- A/B Testing with Practice in Python (Part One)
I learned A/B testing from a Youtube vedio. The link is https://www.youtube.com/watch?v=Bu7OqjYk0jM. ...
- Spfa【p3385】【模板】负环(spfa)
顾z 你没有发现两个字里的blog都不一样嘛 qwq 题目描述 毒瘤数据要求判负环 分析: 还是融合了不少题解的思想的. 负环定义: 权值和为负的环 //在网络上并没有找到一个官方定义,暂且这么理解. ...
- Map集合-根据宠物昵称查找宠物
package collection; /** * 宠物类 * @author * */ public class Pet { private String name; private String ...
- hdu 1556 Color the ball 线段树
题目链接:HDU - 1556 N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气 ...
- Visio整体移动
同理选中第一列的两个,按向右箭头,整体友谊.
- Delphi 使用 SPcomm 调试串口程序出现总是在程序断开的时候,才发送指令的问题。
问题如上, 在与嵌入式程序串口程序通讯的时候, 总是出现如上问题, 造成的原因把下面的True改成false就可以了. 下图Spcomm的属性页,几个True全改成False再试试
- linux命令详解:basename命令
转:http://www.cnblogs.com/lwgdream/archive/2013/11/05/3407768.html 前言 bashname命令用于获取路径中的文件名或路径名(获取的时候 ...
- zookeeper 学习笔记3
ZooKeeper 允许客户端向服务端注册一个 Watcher 监听, ZooKeeper 允许客户端向服务端注册一个 Watcher 监听, ZooKeeper 允许客户端向服务端注册一个 Watc ...
- 在eclipse上部署openfire 3.9.1源码,並配置openfire
参考文章:https://my.oschina.net/u/1409622/blog/205603 在网上找了很久部署openfire源码的文章,由于我使用的是最新的3.9.1源码,试了很多种部署方法 ...