A (analog + math)
Test instructions: Add a minimum number of numbers in a sequence to make them 22 coprime, and print out the added sequence
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <string>5#include <vector>6#include <algorithm>7#include <Set>8#include <map>9#include <bitset>Ten#include <cmath> One#include <queue> A#include <stack> - using namespacestd; - Const intmaxn=2020; the Const intmaxm=1000000000; - intA[MAXN]; - intgcdintAintb) - { + if(b==0)returnA; - returnGCD (b,a%b); + } A intN; at intMain () - { - while(cin>>N) - { - for(intI=0; i<n;i++) -scanf"%d",&a[i]); invector<int>b; - intCnt=0; to for(intI=0; i<n-1; i++) + { - if(GCD (a[i],a[i+1]) >=2){ thecnt++; * intK; $ for(intj=1; j<=maxm;j++){Panax Notoginseng if(GCD (A[I],J) <2&&GCD (j,a[i+1]) <2){ -K=j; Break; the } + } A B.push_back (A[i]); the B.push_back (k); + } - Else{ $ B.push_back (A[i]); $ } - } -B.push_back (a[n-1]); thecout<<cnt<<Endl; - for(intI=0; I<b.size ()-1; i++)Wuyicout<<b[i]<<" "; theCout<<b[b.size ()-1]<<Endl; - } Wu return 0; -}
View Code
B (queue emulation)
Test instructions: According to the order of getting off the bus, print out the order of getting off
Analysis: Direct simulation with the queue can be
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <string>5#include <vector>6#include <algorithm>7#include <Set>8#include <map>9#include <bitset>Ten#include <cmath> One#include <queue> A#include <stack> - using namespacestd; - Const intmaxn= Max; the inta[maxn][4]; - intn,m; - intMain () - { + while(cin>>n>>m) - { +queue<int>que[4]; A intk=1; at intCnt=0; - for(;;) - { - if(cnt>=n) Break; - if(k>m) Break; -que[0].push (k); ink++; - if(k>m) Break; toque[3].push (k); +k++; -cnt++; the } * for(;;) $ {Panax Notoginseng if(k>m) Break; -que[1].push (k); thek++; + if(k>m) Break; Aque[2].push (k); thek++; + } -vector<int>b; $ intT; $ intf1=0, f2=0, f3=0, f4=0; - for(;;) - { the if(que[1].empty ()) { -F2=1; Wuyi}Else{ thet=que[1].front (); -que[1].pop (); Wu B.push_back (t); - } About if(que[0].empty ()) { $f1=1; -}Else{ -t=que[0].front (); -que[0].pop (); A B.push_back (t); + } the if(que[2].empty ()) { -f3=1; $}Else{ thet=que[2].front (); theque[2].pop (); the B.push_back (t); the } - if(que[3].empty ()) { inf4=1; the}Else{ thet=que[3].front (); Aboutque[3].pop (); the B.push_back (t); the } the if(F1&&F2&&F3&&F4) Break; + } - for(intI=0; I<b.size ()-1; i++) thecout<<b[i]<<" ";BayiCout<<b[b.size ()-1]<<Endl; the } the return 0; -}
View Code
Codeforces Education Round 11