[atcoder] agc86 D
来源:互联网 发布:淘宝客鹊桥是什么意思 编辑:程序博客网 时间:2024/06/05 03:53
D - Non-decreasing
题目链接:Non-decreasing
题目大意:
给一个长度为[Math Processing Error]的序列。 每次可以选择两个数[Math Processing Error], 把[Math Processing Error]加到[Math Processing Error]上。最终使得a序列不递降, 题目保证[Math Processing Error]次有解。 输出操作个数以及操作方案。
数据范围:
[Math Processing Error]
[Math Processing Error]
解题思路:
这道题比赛的时候没想出来。C题5分钟写完就挂机了。。 比赛完了之后看了别的代码瞬间理解。
其实如果这个题[Math Processing Error]全是正数或者全是负数, 应该都能想到从左往右或者从右到左累加一次, 即操作了n-1次, 就符合条件了.但是现在有正有负, 又不难发现, 只需要记录绝对值最大的数, 把这n个数都加上这个绝对值最大的数, 他们就符号统一了, 这个操作为n次, 所以题目才能保证在2n次肯定有解.
AC代码:
/******************************************** *Author* :ZZZZone *Created Time* : 一 12/11 20:46:20 2017 * Ended Time* : 一 12/11 21:04:29 2017*********************************************/#include<cstdio>#include<cstring>#include<algorithm>#include<cstdlib>#include<cmath>#include<iostream>using namespace std;int n;int a[55];int main(){ scanf("%d", &n); int p = 0; for(int i = 1; i <= n; i++){ scanf("%d", &a[i]); if(abs(a[i]) >= abs(a[p])) p = i; } printf("%d\n", 2 * n - 1); for(int i = 1; i <= n; i++) printf("%d %d\n", p, i); if(a[p] > 0) for(int i = 1; i < n; i++) printf("%d %d\n", i, i + 1); else for(int i = n; i > 1; i--) printf("%d %d\n", i, i - 1); return 0;}
阅读全文
0 0
- [atcoder] agc86 D
- Atcoder D
- atcoder 055D D
- atcoder square869120Contest #4 D
- Atcoder 2334 D
- Atcoder ARC 077 D
- AtCoder-RC078 D
- AtCoder 079D Decrease
- atcoder-abc-070D
- atcoder 062D
- Atcoder arc 084 D
- 【AtCoder】(AtCoder Grand Contest 006)D
- AtCoder AtCoder Beginner Contest 063 D
- atcoder AtCoder Regular Contest 084 D
- AtCoder Regular Contest 069 D
- Atcoder 056 D 贪心+二分
- Atcoder Grand Contest 013D
- AtCoder Regular Contest 073 D
- IT时代
- JMeter+Maven+Jenkins
- 购物车管理模块
- 8.5调用函数与数组取负值结束
- recyclerview实现多条目
- [atcoder] agc86 D
- java多线程3-线程的同步与数据传递
- 使用RNN进行图像分类
- PPT 之神器 SmartArt
- android从放弃到精通 第七天 tomorrow
- Uinty学习概述
- 【TensorFlow】神经网络参数与变量(四)
- 笔记
- 【赠书】拨云见日