Codeforces Round #275 (Div. 2) C
2024-09-08 05:40:10
题目传送门: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");
}
}
最新文章
- 导入一些常用命令比如(rz),关闭防火墙外面可以访问
- [转]CSS 表单元素对齐详解
- js生成二维码实例(真实有效)
- BZOJ 1002 [ FJOI 2007 ]
- MSChart参考
- PCA和Softmax分类比较—Mnist与人脸数据集
- git(osx)上的一个git commit无法正确提交的问题
- 1201: [HNOI2005]数三角形 - BZOJ
- 不规则三角网(TIN)(转)
- selenium文件上传的实现
- Android设置背景
- 由Spring框架中的单例模式想到的
- spring整合mybatis错误:class path resource [config/spring/springmvc.xml] cannot be opened because it does not exist
- hibernate 动态多数据库
- Storm入门-Storm与Spark对比
- [转][C#]服务安装卸载命令
- day3 python学习
- shell-保留文件系统下剩余指定数目的文件
- python基础训练题1-列表操作
- FormsAuthentication 使用指南