HDU
来源:互联网 发布:陕西广电网络换门庭 编辑:程序博客网 时间:2024/04/30 12:46
Permutation
Problem Description
A permutation p1,p2,...,pn of 1,2,...,n is called a lucky permutation if and only if pi≡0(mod|pi−pi−2|) for i=3...n .
Now you need to construct a lucky permutation with a givenn .
Now you need to construct a lucky permutation with a given
Input
The first line is the number of test cases.
For each test case, one single line contains a positive integern(3≤n≤105) .
For each test case, one single line contains a positive integer
Output
For each test case, output a single line with n numbers p1,p2,...,pn .
It is guaranteed that there exists at least one solution. And if there are different solutions, print any one of them.
It is guaranteed that there exists at least one solution. And if there are different solutions, print any one of them.
Sample Input
16
Sample Output
1 3 2 6 4 5
题意:很简单。要注意是排列,就所有数字只能用一次。
解题思路:任何数模1,都为0.所以……看代码……
#include<iostream>#include<deque>#include<memory.h>#include<stdio.h>#include<map>#include<string.h>#include<algorithm>#include<vector>#include<math.h>#include<stack>#include<queue>#include<set>using namespace std;typedef long long int ll;int a[100005];int main(){ int t; scanf("%d",&t); while(t--){ int n; scanf("%d",&n); a[1]=1; if(n%2) a[2]=n/2+2; else a[2]=n/2+1; for(int i=3;i<=n;i++) a[i]=a[i-2]+1; for(int i=1;i<n;i++) cout<<a[i]<<" "; cout<<a[n]<<endl; } return 0;}
阅读全文
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- (2)计算1*2*3+3*4*5+......+99*100*101的值。
- 【百度爬虫系列 I】多关键字图片搜索结果汇总
- HTML-3
- Linux查看和修改PATH环境变量的方法
- 加法电路原理
- HDU
- fragment activity 间传值
- Convert BST to Greater Tree
- Netty实战读书笔记(第三章)
- 连续总结第三十二天
- ArcGIS API for JavaScript 通过identifyTask实现按区域选取截图
- 计算两整数的最大值
- 蓝桥杯 历届试题 核桃的数量
- java串口调试助手