Codeforces Round #720 (Div. 2) B. Nastia and a Good Array(被坑好几次)1300
原题链接
题意
给一串数,要把任意两个相邻的数的最大公约数=1
每次可以进行一个操作:
取下标为i, j的数,和任意二数x,y,且min(ai,aj)=min(x,y)
满足上述条件,即可使ai=x,aj=y
限制条件:操作次数 <= n
解析
找到数列最小值,操作完是最小值不变,其余数大小=最小值+(每个数与最小数下标差值)
换句话说:以最小值为中心,两边依次递增、
附:每次以最小值操作可以保证不越界,而且具有稳定性,不会出现操作者的值小于最小值
AC代码
#include <iostream> using namespace std;
typedef long long ll; const int N = 1e5 + 10; ll a[N]; int main()
{
int t;
cin >> t;
while(t --)
{
int n;
cin >> n;
for(int i = 1; i <= n; i ++) cin >> a[i]; a[0] = 0x3f3f3f3f;
int minn = 0;
for(int i=1; i <= n; i ++)
{
if(a[i] < a[minn])
minn = i;
}
ll x1 = a[minn], x2 = a[minn]; cout << n-1 << endl;
for(int i = minn; i < n; i ++)
{
cout << minn << ' '<< i+1 <<' ' << a[minn] << ' '<< 1+x1<<endl;
x1 ++;//这里, 从最小到后面
}
for(int i = minn; i > 1; i --)
{
cout << i-1 << ' '<< minn <<' ' << x2+1 << ' '<< a[minn]<<endl;
x2 ++;//这里, 从最小到前面
}
}
return 0;
}
Codeforces Round #720 (Div. 2) B. Nastia and a Good Array(被坑好几次)1300的更多相关文章
- Codeforces Round #312 (Div. 2)B. Amr and The Large Array 暴力
B. Amr and The Large Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...
- Codeforces Round #312 (Div. 2) B.Amr and The Large Array
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller. ...
- Codeforces Round #361 (Div. 2)——B. Mike and Shortcuts(BFS+小坑)
B. Mike and Shortcuts time limit per test 3 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #354 (Div. 2)-C. Vasya and String,区间dp问题,好几次cf都有这种题,看来的好好学学;
C. Vasya and String time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #581 (Div. 2) B. Mislove Has Lost an Array (贪心)
B. Mislove Has Lost an Array time limit per test1 second memory limit per test256 megabytes inputsta ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
随机推荐
- 程序设计基础·Java学习笔记·面向对象(上)
Java程序设计基础之面向对象(上) (自适应学习进度而进行记录的笔记,希望有一些小小的用处吧(^∀^●)ノシ) (新人上路,望多指教,如有错误,望指正,万分感谢(o゚v゚)ノ) 目录 一.面向对象 ...
- zabbix图形中文乱码
别的贴子都是说到修改/usr/share/zabbix/include/defines.inc.php中的 define('ZBX_FONT_NAME', 'msyh'); define('ZBX_G ...
- RDMA相关的技术网站
https://www.cnblogs.com/vlhn/p/7909893.html https://www.cnblogs.com/vlhn/ 这个家伙的博客写的还不错,可以参考.
- javascript函数 (二 定义函数的三种方法)
javascript定义函数(声明函数)可以有三种方法:正常方法.构造函数.函数直接量 <html><head></head><body> <sc ...
- HTTP发展史,HTTP1.1与HTTP2.0的区别
前言 我们知道HTTP是浏览器中最重要且使用最多的协议,它不仅是浏览器与服务端的通信语言,更是互联网的基石.随着浏览器的不断更新迭代,HTTP为了适应技术的更新也在不断进化,学习HTTP的最佳途径就是 ...
- 为什么JVM要用到压缩指针?Java对象要求8字节的整数倍?
前言 前两天在一个帖子中看到一道面试题: 堆内存超过32G时,为什么压缩指针失效? 之前没有了解过这方面的知识,于是开始google起来,但当我翻看了不下一页的帖子,我都仍然没有搞懂,因为好多答案给我 ...
- Python -用虚拟环境保存库文件
如果你同时负责多个 Python 项目,或者想要轻松打包某个项目及其关联的库文件,再或者你担心已安装的库之间可能有冲突,那么你可以安装一个 Python 虚拟环境来分而治之.当一个 Python 库不 ...
- Makefile学习(一)
objects = main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o ...
- 修道士与野人问题(BFS广度搜索)
#include "iostream.h" #include "string.h" //定义一个状态节点 typedef struct //存储各个状态 { i ...
- java-設計模式-生成器
生成器模式Bulider 使你能够分步骤创建复杂对象. 该模式允许你使用相同的创建代码生成不同类型和形式的对象. 将一个复杂对象的构造与它的表示分离,使同样的构建过程可以创建不同的表示. 将一个复杂的 ...