codeforces 622D Optimal Number Permutation 思维
来源:互联网 发布:产品360度展示软件 编辑:程序博客网 时间:2024/06/04 18:33
题意:有n个数,要求每个数出现2次,位置分别为xi、yi(xi < yi),定义di = yi-xi。让你找到一个全排列使得sigma((n-i) * |di+i-n|)最小。
因为推不出单调性,也可以说是非线性的单调性 所以直观猜测为0.那么每个数都是 n-i相隔。。所以 开始写。。写了好久
#include <bits/stdc++.h>using namespace std;const int maxn=1e6+10;int num[maxn];int main(){ int n; cin>>n; int i; int len=n; int tot=1; memset(num,0,sizeof(num)); for( i=1;i<n&&tot<n;i++) { num[i]=num[len-i+1]=tot; tot+=2; } tot=2; len=n+1+n-tot; for(int i=1;i<n&&tot<n;i++) { num[n+i]=num[len-i+1]=tot; tot+=2; } for(int i=1;i<=2*n;i++) if(num[i]==0) num[i]=n; for(int i=1;i<=2*n;i++) printf("%d ",num[i]); printf("\n");}
阅读全文
0 0
- codeforces 622D Optimal Number Permutation 思维
- Codeforces 622D Optimal Number Permutation 【贪心】
- Codeforces 622D Optimal Number Permutation(构造)
- CodeForces 622D Optimal Number Permutation(构造)
- CodeForces 622 D.Optimal Number Permutation(构造)
- Codeforces 622D Optimal Number Permutation【贪心+构造】
- Optimal Number Permutation CodeForces
- Educational Codeforces Round 7 D. Optimal Number Permutation(构造)
- Educational Codeforces Round 7--D. Optimal Number Permutation
- Codeforces edu 7 D. Optimal Number Permutation 构造
- codeforces edu round7 D Optimal Number Permutation构造
- Educational Codeforces Round 7-D. Optimal Number Permutation
- D. Optimal Number Permutation(构造)
- codeforces622D Optimal Number Permutation
- cf#ecr7-D - Optimal Number Permutation-构造+脑洞
- Codeforces 660D Number of Parallelograms 【思维】
- codeforces_622D. Optimal Number Permutation(构造)
- Codeforces 864D D. Make a Permutation!【思维+线段树+二分+这是一个煞笔做法】
- #include和#import "" <>和@class区别
- merge语句
- 1.1如何创建可引导Ubuntu的启动U盘
- linux中设置静态ip
- 循环和catch块
- codeforces 622D Optimal Number Permutation 思维
- 收藏一个镜像站
- Struts2_输出带有占位符的国际化信息
- angular测试
- 记忆安卓事件分发,一表概括。
- 【CSS标签的分类和选择】
- 结构体排序-10-排序5 PAT Judge (25分)
- 简单工厂模式与纯虚函数的应用
- 循环不变式的理解