原题链接

Problem - B - Codeforces

题意

给一串数,要把任意两个相邻的数的最大公约数=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的更多相关文章

  1. 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 ...

  2. 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. ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  8. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  9. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

随机推荐

  1. vim设置自动添加头部注释

    #自己改了改vim开头文件,如下图# 友友们可以直接修改·SetTitle() if v:lang =~ "utf8$" || v:lang =~ "UTF-8$&quo ...

  2. python练习册 每天一个小程序 第0012题

    # -*-coding:utf-8-*- def test(content): text = content flag = 0 with open('filtered_words.txt') as f ...

  3. Xshell 连接虚拟机OS Linux 设置静态ip ,网络配置中无VmWare8 的解决办法

    前序:最近开始研究Hadoop平台的搭建,故在本机上安装了VMware workstation pro,并创建了Linux虚拟机(centos系统),为了方便本机和虚拟机间的切换,准备使用Xshell ...

  4. Java Arrays.asList(0,1,2,3,4,5,6,7,8,9).parallelStream().forEach 进行循环获取HttpServletRequest的为Null的解决方案

    Arrays.asList(0,1,2,3,4,5,6,7,8,9).parallelStream().forEach() parallelStream是并行执行流的每个元素,也就是多线程执行,这样就 ...

  5. Eclipse建立Web项目,手动生成web.xml文件

    相关文章:https://blog.csdn.net/ys_code/article/details/79156188(Web项目建立,手动生成web.xml文件

  6. 说出 5 个 JDK 1.8 引入的新特性?

    Java 8 在 Java 历史上是一个开创新的版本,下面 JDK 8 中 5 个主要的特性: Lambda 表达式,允许像对象一样传递匿名函数 Stream API,充分利用现代多核 CPU,可以写 ...

  7. 学习Apache(五)

     apache目前主要有两种模式:prefork模式和worker模式: 1)prefork模式(默认模式) prefork是Unix平台上的默认(缺省)MPM,使用多个子进程,每个子进程只有一个线程 ...

  8. 自定义XML文件模板步骤

  9. C语言小游戏——2048

      2048   2048这款游戏的玩法很简单,每次可以选择上下左右滑动,每滑动一次,所有的数字方块都会往滑动的方向靠拢,系统也会在空白的地方乱数出现一个数字方块,相同数字的方块在靠拢.相撞时会相加. ...

  10. 微信小程序——gulp处理文件

    懒癌直接贴代码,想写在写因为最近搞了一下小程序,直接使用微信的开发者工具搞感觉有点不习惯,并且看了几篇给小程序瘦身的博客,决定给自己的项目做一套配置文件,使用gulp来支持sass scss文件编译以 ...