Codeforces Round #720 (Div. 2)-B.Nastia and a Good Array-构造
Posted Chivas_/Regal
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #720 (Div. 2)-B.Nastia and a Good Array-构造相关的知识,希望对你有一定的参考价值。
题目:
思路:
本来还以为这是个贪心让求最小变换次数了,结果发现不是,随便一胡就过去了 这就是道构造题
所以
我们可以发现,最小的位置上的数绝对是构造完的数列中最小的那个数
所以最小的数肯定要保留
由于__gcd(x, x + 1) == 1,所以我们可以利用此性质做n - 1次变换
即由最小值所在的位置开始
向两侧各做一个递增的差值为1的等差数列
不贪心地,暴力做就行了
代码:
/*
____________________________________________________________________________________
/ ______| | | |____ ___|\\ \\ / / \\ | |
/ / | | | | | | \\ \\ / / /\\ \\ | _______|
| | | |___| | | | \\ \\ / / / \\ \\ | |______
| | | ___ | | | \\ \\/ / /____\\ \\ |_______ |
| | | | | | | | \\ / ________ \\ ______| |
\\ \\______| | | |___| |___ \\ / / \\ \\ | |
Author : _\\________|___|___|___|___________|_____\\__/__/__________\\__\\|___________|
————————————————————————————————————————————————————————————————————————————————————
*/
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <stack>
#include <queue>
#include <cmath>
#include <utility>
#include <map>
#include <set>
#define G 10.0
#define LNF 1e18
#define EPS 1e-6
#define PI acos(-1.0)
#define INF 0x7FFFFFFF
#define ll long long
#define ull unsigned long long
#define LOWBIT(x) ((x) & (-x))
#define LOWBD(a, x) (lower_bound(ALL(a), (x)) - (a).begin())
#define UPPBD(a, x) (upper_bound(ALL(a), (x)) - (a).begin())
#define TEST(a) cout << "---------" << a << "---------" << '\\n'
#define Chivas int main()
#define Regal exit(0)
#define SP system("pause")
#define IOS ios::sync_with_stdio(false)
#define map unordered_map
#define PB(x) push_back(x)
#define ALL(a) ((a).begin(),(a).end())
#define MEM(a, b) memset(a, b, sizeof(a))
#define EACH_CASE(cass) for (cin >> cass; cass; cass--)
using namespace std;
template<typename T> inline T MAX(T a, T b){return a > b? a : b;}
template<typename T> inline T MIN(T a, T b){return a > b? b : a;}
template<typename T> inline void SWAP(T &a, T &b){T tp = a; a = b; b = tp;}
template<typename T> inline T GCD(T a, T b){return b > 0? gcd(b, a % b) : a;}
template<typename T> inline pair<T, T> MaxInVector_ll(vector<T> vec){T MaxVal = -LNF, MaxId = 0;for(int i = 0; i < (int)vec.size(); i ++) if(MaxVal < vec[i]) MaxVal = vec[i], MaxId = i; return {MaxVal, MaxId};}
template<typename T> inline pair<T, T> MinInVector_ll(vector<T> vec){T MinVal = LNF, MinId = 0;for(int i = 0; i < (int)vec.size(); i ++) if(MinVal > vec[i]) MinVal = vec[i], MinId = i; return {MinVal, MinId};}
template<typename T> inline pair<T, T> MaxInVector_int(vector<T> vec){T MaxVal = -INF, MaxId = 0;for(int i = 0; i < (int)vec.size(); i ++) if(MaxVal < vec[i]) MaxVal = vec[i], MaxId = i; return {MaxVal, MaxId};}
template<typename T> inline pair<T, T> MinInVector_int(vector<T> vec){T MinVal = INF, MinId = 0;for(int i = 0; i < (int)vec.size(); i ++) if(MinVal > vec[i]) MinVal = vec[i], MinId = i; return {MinVal, MinId};}
template<typename T> inline pair<map<T, T>, vector<T> > DIV(T n){T nn = n;map<T, T> cnt;vector<T> div;for(ll i = 2; i * i <= nn; i ++){while(n % i == 0){if(!cnt[i]) div.push_back(i);cnt[i] ++;n /= i;}}if(n != 1){if(!cnt[n]) div.push_back(n);cnt[n] ++;n /= n;}return {cnt, div};}
struct node{
ll j;
ll k;
ll x;
ll y;
};
inline void solve(){
ll n; cin >> n;
ll Minid = 0, Minval = LNF;//最小的值的位置,最小的值
vector<ll> a;
for(ll i = 0, x; i < n; i ++){
cin >> x;
a.PB(x);
}
pair<int, int> p = MinInVector_ll(a);
Minid = p.second, Minval = p.first;
if(n == 1){
cout << "0" << endl;
return;
}
vector<node> put;
for(ll i = Minid + 1; i < n; i ++){
a[i] = a[i - 1] + 1;
put.push_back({i, Minid, a[i], Minval});
}
for(ll i = Minid - 1; i >= 0; i --){
a[i] = a[i + 1] + 1;
put.push_back({i, Minid, a[i], Minval});
}
cout << put.size() << endl;
for(int i = 0; i < (int)put.size(); i ++){
cout << put[i].j + 1 << " " << put[i].k + 1 << " " << put[i].x << " " << put[i].y << endl;
}
}
Chivas{
int cass;
IOS;
EACH_CASE(cass){
solve();
}
Regal;
}
以上是关于Codeforces Round #720 (Div. 2)-B.Nastia and a Good Array-构造的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #720 (Div. 2)Codeforces-1521ABC
Codeforces Round #720 (Div. 2) ABCDE题解
Codeforces Round #720 (div2) AB
Codeforces Round #720 (Div. 2), B. Nastia and a Good Array
Codeforces Round #720 (Div. 2) A. Nastia and Nearly Good Num