CF contest 892 D题 Gluttony
来源:互联网 发布:淘宝收货地址怎么定位 编辑:程序博客网 时间:2024/05/29 18:40
传送门
//题意:对于给定的一个长度为n的a序列, 重排a序列构造一个b序列, 使得b序列中任意一个连续区间中的前缀和不相等(除去全体的前缀和).
//思路:因为题目中给的是n个不同的数, 所以首先一定有解, 那么如何构造了, 我么可以假设一个序列 1 2 3 4 5 那么如何重构b序列了, 我们可以发现每一个数我们可以选择一个比它小的数相对应, 如果是最小的那个数就选最大的那个数与之对应, 这样构造的b序列一定是符合题意的 !!!
AC Code
int a[30],b[30],p[30];bool cmp(int x,int y) { return a[x] < a[y];}void solve(){ int n; while(~scanf("%d",&n)) { for(int i=1;i<=n;i++) { scanf("%d",&a[i]); p[i] = i; } sort(p+1,p+1+n,cmp); b[p[1]] = a[p[n]]; for(int i=2;i<=n;i++) { b[p[i]] = a[p[i-1]]; } for(int i=1;i<=n;i++) { printf("%d%c",b[i],i==n?'\n':' '); } }}
阅读全文
0 0
- CF contest 892 D题 Gluttony
- CF 892D Gluttony 构造
- CF#446 Gluttony(思维题)
- Codeforces 892 D. Gluttony (思维)
- Codeforces Round #446 (Div. 2) D. Gluttony
- codeforces contest 779 D题
- CF 345 div2 D题
- CF 632 D 技巧题
- Codeforces Round #446 (Div. 2) D. Gluttony (构造 贪心)
- Codeforces Round #446 (Div. 2) D. Gluttony 找规律
- Codeforces Round #446 (Div. 2) D. Gluttony 构造 置换
- CF contest/389
- CF Contest Balloons
- codeforces -891B Gluttony 排列,构造题
- codeforces -891B Gluttony 排列,构造题
- Bayan 2015 Contest Warm Up (D题)
- AtCoder Grand Contest 018--D题
- CF #109 div2 D题 Colliders
- .net linq
- Java文件压缩代码
- Linux下文件描述符配置
- Nodejs一些初识问题总结
- ZCMU1416
- CF contest 892 D题 Gluttony
- 秋招面经总结
- 1到10所有数的立方
- Leetcode 236. Lowest Common Ancestor of a Binary Tree
- 三大主流软件负载均衡器对比(LVS VS Nginx VS Haproxy)
- 模拟shell实现su命令(切换用户)
- Dom解析xml入门实例!!!!!!!!!!
- div,css
- c语言_猜数字游戏