CODECHEF Minimum Good Permutation
来源:互联网 发布:驾照考试网络预约平台 编辑:程序博客网 时间:2024/06/07 22:59
题目链接:https://www.codechef.com/SEPT17/problems/MINPERM
求最小的错排
奇偶要分类讨论
偶数个时把
偶数个时前面一样,后面三个特殊处理,
贴代码
#include<cstdio>#include<cstring>using namespace std;int n,m,Q;int main(){// freopen("2.in","r",stdin);// freopen("2.out","w",stdout); scanf("%d",&Q); while (Q--){ scanf("%d",&n); m=n%2==0?n:n-3; for (int i=1;i<=m;i++)i%2==0?printf("%d ",i-1):printf("%d ",i+1); if (n%2==1)printf("%d %d %d ",n-1,n,n-2); printf("\n"); } return 0;}
【写的有漏洞的,欢迎路过大神吐槽】
2017/09/11 19:27:13
Ending.
阅读全文
0 0
- CODECHEF Minimum Good Permutation
- codechef Permutation Cycles 题解
- Range Minimum Queries (CodeChef ANDMIN )
- CodeChef:Good Pairs(dp & 二进制)
- CodeChef:Minimum SubArray(线段树最值)
- Good Bye 2014--B. New Year Permutation
- Good Bye 2014 B. New Year Permutation
- 【codechef】Chef and A Large Permutation(技巧题)
- CodeChef
- CodeChef
- CodeChef
- CodeChef
- (CodeChef
- CodeChef
- CodeChef
- CodeChef
- CodeChef
- CodeChef
- Android 简单的listview分页加载
- 《PHP和MySQL WEB开发》第三章笔记
- 项目工作量估算的专家法
- find your present (2)
- hdu6201-搜索|最长路-transaction transaction transaction
- CODECHEF Minimum Good Permutation
- (CSU
- Servlet程序及Servlet的应用
- mybatis的selectKey功用
- E/ExoPlayerImplInternal: Source error.
- 《TCP IP网络编程》尹圣雨----8.第五章源码展示
- Linux命令分析:find
- bzoj2618 [Cqoi2006]凸多边形(半平面+S)
- Count and say[easy on LeetCode]