AtCoder Beginner Contest 081 D
来源:互联网 发布:音效管理器软件下载 编辑:程序博客网 时间:2024/06/06 15:50
D - Non-decreasing
Time limit : 2sec / Memory limit : 256MB
Score : 600 points
Problem Statement
Snuke has an integer sequence, a, of length N. The i-th element of a (1-indexed) is ai.
He can perform the following operation any number of times:
Operation: Choose integers x and y between 1 and N (inclusive), and add ax to ay.
He would like to perform this operation between 0 and 2N times (inclusive) so that a satisfies the condition below. Show one such sequence of operations. It can be proved that such a sequence of operations always exists under the constraints in this problem.
Condition: a1≤a2≤…≤aN
Constraints
2≤N≤50
−106≤ai≤106
All input values are integers.
Input
Input is given from Standard Input in the following format:
N
a1 a2 … aN
Output
Let m be the number of operations in your solution. In the first line, print m. In the i-th of the subsequent m lines, print the numbers x and y chosen in the i-th operation, with a space in between. The output will be considered correct if m is between 0 and 2N (inclusive) and a satisfies the condition after the m operations.
Sample Input 1
3
-2 5 -1
Sample Output 1
2
2 3
3 3
After the first operation, a=(−2,5,4).
After the second operation, a=(−2,5,8), and the condition is now satisfied.
Sample Input 2
2
-1 -3
Sample Output 2
1
2 1
After the first operation, a=(−4,−3) and the condition is now satisfied.
Sample Input 3
5
0 0 0 0 0
Sample Output 3
0
The condition is satisfied already in the beginning.
题意: 给你n个数,让你通过移位相加,使得数列非递减
分析: 找到绝对值最大的值,如果该值为正,所有数都加上该值,使得所有数都大于零,然后从左向右扫一遍即可,如果是负数,从右向左扫一遍即可
参考代码
#include<bits/stdc++.h>using namespace std;int main(){ ios_base::sync_with_stdio(0); int n;cin>>n; int ma = 0; int inx = -1; for(int i = 1;i <= n;i++) { int x;cin>>x; if(abs(x) > abs(ma)) { ma = x; inx = i; } } if(inx == -1) cout<<0<<endl; else { cout<<2*n-1<<endl; for(int i = 1;i <= n;i++) { cout<<inx<<' '<<i<<endl; } if(ma > 0) { for(int i = 1;i < n;i++) { cout<<i<<' '<<i+1<<endl; } } else { for(int i = n;i > 1;i--) { cout<<i<<' '<<i-1<<endl; } } } return 0;}
- 如有错误或遗漏,请私聊下UP,thx
- AtCoder Beginner Contest 081 D
- AtCoder Beginner Contest 081 D
- AtCoder Beginner Contest 081
- AtCoder Beginner Contest 081
- AtCoder Beginner Contest 061 D
- AtCoder Beginner Contest 066 D
- AtCoder Beginner Contest 067 D
- AtCoder Beginner Contest 067 D
- AtCoder Beginner Contest 068 D
- AtCoder Beginner Contest 069 D
- AtCoder Beginner Contest 070-D
- AtCoder Beginner Contest 070 D
- AtCoder Beginner Contest 071 D
- AtCoder Beginner Contest 075 D
- AtCoder Beginner Contest 076 D
- AtCoder AtCoder Beginner Contest 063 D
- AtCoder Beginner Contest 081 C
- AtCoder Beginner Contest 058 D井井井 / ###【“贡献”】
- Neo4j_嵌入模式&服务器模式
- JS实现的4种数字千位符格式化方法(转)
- Mysql数据库各类知识总结
- Ajax方式上传文件
- java基础-反射3(反射,反射创建对象,操作对象属性,调用对象方法)
- AtCoder Beginner Contest 081 D
- java线程生命周期
- 网络流算法(Network Flow)
- 《算法导论》学习笔记Chapter11散列表
- pixhawk姿态控制
- 冒个泡,留个纪念
- python 将多个图片合成为一个视频
- java理解实例和类成员
- 毕业一年多,未来的路该如何走?