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 常见排序算法(纯代码)
目录 汇总 1. 冒泡排序 2. 选择排序 3. 插入排序 4. 快速排序 5. 归并排序 6. 希尔排序 6.1 希尔-冒泡排序(慢) 6.2 希尔-插入排序(快) 7. 堆排序 8. 计数排序 9 ...
- vue学习过程总结(05) - vue的重要插件vue-router
vue-router的中文文档:https://router.vuejs.org/zh/installation.html(基于文档的摘抄) 1.vue中的组件与插件 转载:https://blog. ...
- Mybatis入门实例解析
写在前面:本文全程根据Mybatis官网进行入门讲解.毫无疑问,官方文档是学习这门技术最权威的资料,与此同时我们也知道官方文档对待入门小白基本上不太友好,没有入门demo.开篇就是小白们不懂的内容.有 ...
- Spring ---Spring专题(一)
1. Spring简介 1.1 什么是Spring spring是分层的java SE/EE应用full-stack(全栈)轻量级开源框架,以IOC(Inverse Of Control:反转控制)和 ...
- 查找bug的一些经验总结
项目开发中遇到的bug解决经验总结 今天在项目开发中遇到了两个很难解决的bug,我把我的思路记录下来,以供之后遇到bug时,提供一些思路: 编译通过,但总结"core dumped" ...
- 详细描述一下 Elasticsearch 索引文档的过程?
协调节点默认使用文档 ID 参与计算(也支持通过 routing),以便为路由提供合适的分片. shard = hash(document_id) % (num_of_primary_shards) ...
- 什么是 Spring 配置文件?
Spring 配置文件是 XML 文件.该文件主要包含类信息.它描述了这些类是如何 配置以及相互引入的.但是,XML 配置文件冗长且更加干净.如果没有正确规划 和编写,那么在大项目中管理变得非常困难.
- 介绍一下 WebApplicationContext?
WebApplicationContext 是 ApplicationContext 的扩展.它具有 Web 应用 程序所需的一些额外功能.它与普通的 ApplicationContext 在解析主题 ...
- Netty学习摘记 —— 单元测试
本文参考 本篇文章是对<Netty In Action>一书第九章"单元测试"的学习摘记,主要内容为使用特殊的 Channel 实现--EmbeddedChannel来 ...
- Python - list、tuple类型