当前位置: 移动技术网 > IT编程>开发语言>C/C++ > agc007B - Construct Sequences(构造)

agc007B - Construct Sequences(构造)

2018年09月26日  | 移动技术网IT编程  | 我要评论

cqwb,流行歌曲大全,李伊娜

题意

给出一个$1-n$的排列$p$,构造两个数组$a, b$满足

sol

发现我的水平也就是能做一做0-699的题。。。。

直接构造两个等差数列$a, b$,公差为$20000$

然后从小到大枚举$p$,让考前的$a$减去一个较大的数就行了。。

#include<bits/stdc++.h>
#define ll long long  
using namespace std;
const int maxn = 20001, base = 20009;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int n, a[maxn], b[maxn];
int main() {
    n = read();
    for(int i = 1; i <= n; i++) a[i] = base * i;
    for(int i = 1; i <= n; i++) b[i] = base * (n - i + 1);
    for(int i = 1; i <= n; i++) {
        int x = read();
        a[x] -= (n - i + 1);
    }
    for(int i = 1; i <= n; i++) printf("%d ", a[i]); puts("");
    for(int i = 1; i <= n; i++) printf("%d ", b[i]);
    return 0;
}

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网