Codeforces_959D_Mahmoud and Ehab and another array construction task(数学+贪心)

版权声明: https://blog.csdn.net/yyy_3y/article/details/79965564

传送门

题意:给你一个序列A,让你求一个序列B,满足以下情况:
1.B的字典序比A大
2.Bi>=2
3.B中的没两个数都两两互质。

思路:先预处理质因数。B中满足两两互质等价于B中没有相同的质因数。所以对于每个数看,他的质因数有没有在之前出现过,出现过就找 下一个,如果找到的数和起始的不一样的话,之后的数只需要从最小的质数开始就行。

#include<bits/stdc++.h>
#define debug(a) cout << #a << " " << a << endl
#define LL long long
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-6
const int N=2e6+7;
using namespace std;
bool vis[N];
vector<int> stk[N];
void init()
{
    for(int i=2;i<N;i++){
        if(!vis[i]){
            for(int j=i;j<N;j+=i) vis[j]=1,stk[j].push_back(i);
        }
    }
    memset(vis,0,sizeof(vis));
}
int solve(int x)
{
    for(auto &i:stk[x])
        if(vis[i]) return 0;
    for(auto &i:stk[x])
        vis[i]=1;
    return 1;
}
int main ()
{
    //yyy_3y
    //freopen("1.in","r",stdin);
    int n;scanf("%d",&n);
    init();
    int flag=1;
    int q=2;
    for(int i=1;i<=n;i++){
        int x; scanf("%d",&x);
        int tmp=x;
        if(flag){
            while(!solve(tmp))tmp++;
            if(tmp!=x) flag=0;
            printf("%d ",tmp);
        }else{
            while(!solve(q)) q++;
            printf("%d ",q);
        }
    }
    return 0;
}
阅读更多

Another Very Easy Task

02-14

This task is so easy that the description is omitted.nnSample InputnnA numeronym is a number-based word.nnMost commonly, a numeronym is a word where a number is used to form annabbreviation (albeit not an acronym or an initialism). Pronouncing thenletters and numbers may sound similar to the full word: "K9" for "canine"n(phonetically: "kay" + "nine"). A similar example in French is "K7" forn"cassette" (phonetically: "ka" + "sept").nnAlternatively, the letters between the first and last are replaced by annumber representing the number of letters omitted, such as "i18n" forn"internationalization". Sometimes the last letter will also be countednand omitted.nnAccording to Tex Texin, the first numeronym of this kind was "S12n", thenelectronic mail account name given to DEC employee Jan Scherpenhuizen byna system administrator because his surname was too long to be an accountnname. Colleagues who found Jan's name unpronounceable often referred tonhim verbally as "S12n". The use of such numeronyms became part of DECncorporate culture.nSample OutputnnA n7m is a n4r-b3d w2d.nnM2t c6y, a n7m is a w2d w3e a n4r is u2d to f2m anna10n (a4t n1t an a5m or an i8m). P9g t1enl5s a1d n5s m1y s3d s5r to t1e f2l w2d: "K9" f1r "c4e"n(p10y: "k1y" + "n2e"). A s5r e5e in F4h is "K7" f1rn"c6e" (p10y: "ka" + "s2t").nnA11y, t1e l5s b5n t1e f3t a1d l2t a1e r6d by ann4r r10g t1e n4r of l5s o5d, s2h as "i18n" f1rn"i18n". S7s t1e l2t l4r w2l a2o be c5dna1d o5d.nnA7g to T1x T3n, t1e f3t n7m of t2s k2d w1s "S12n", t1ene8c m2l a5t n2e g3n to D1C e6e J1n S12n byna s4m a11r b5e h1s s5e w1s t1o l2g to be an a5tnn2e. C8s w1o f3d J1n's n2e u13e o3n r6d tonh1m v6y as "S12n". T1e u1e of s2h n8s b4e p2t of D1Cnc7e c5e.

没有更多推荐了,返回首页