2019 NOIP 夏令营(模拟赛1)
一来到夏令营,第一天上机就考试,
哎,简直不让人活了
这难道是给我们的见面礼???
A
https://www.luogu.org/problemnew/show/P1197
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include<string> using namespace std; int n,m,q,len=0; int last[400010],p[400010],father[400010],ans[400010]; struct node { int x; int y; int next; } qwq[1000010]; bool bz[400010]; void add(int x,int y) { qwq[++len].x=x; qwq[len].y=y; qwq[len].next=last[x]; last[x]=len; } int find(int x) { if(father[x]!=x) { father[x]=find(father[x]); } return father[x]; } int main() { int x,y; scanf("%d %d",&n,&m); for(int i=0;i<=n;i++) { last[i]=-1; father[i]=i; } for(int i=1;i<=m;i++) { scanf("%d %d",&x,&y); add(x,y); add(y,x); } scanf("%d",&q); for(int i=1;i<=q;i++) { scanf("%d",&p[i]); bz[p[i]]=true; } int tot1=n-q; m=m<<1; for(int i=1;i<=m;i++) { int x=qwq[i].x,y=qwq[i].y,t1=find(x),t2=find(y); if(!bz[x]&&!bz[y]&&t1!=t2) { tot1--; father[t1]=t2; } } ans[q+1]=tot1; for(int k=q;k>=1;k--) { int x=p[k]; bz[x]=false; tot1++; for(int i=last[x];i!=-1;i=qwq[i].next) { int t1=find(x),y=qwq[i].y,t2=find(y); if(!bz[y]&&t1!=t2) { tot1--; father[t1]=t2; } } ans[k]=tot1; } for(int i=1;i<=q+1;i++) { printf("%d\n",ans[i]); } return 0; }
B
https://www.luogu.org/problemnew/show/CF804B
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int Mod=1e9+7; int main() { string s; cin>>s; int xx=0; int sum1=0; int len=s.length(); for(int i=len-1;i>=0;i--) { if(s[i]=='a') { sum1=(sum1+xx)%Mod; xx=xx*2%Mod; } else if(s[i]=='b') { xx++; } } cout<<sum1<<endl; return 0; }
C
https://www.luogu.org/problemnew/show/CF798C
#include<iostream> #include<cstdio> #include<cmath> using namespace std; int gcd(int x,int y) { if(y==0) { return x; } else { return gcd(y,x%y); } } int a[100001]; int main() { int n; cin>>n; for(int i=0;i<n;i++) { cin>>a[i]; } int xx=0; int ans=0; int t; for(int i=0;i<n;i++) { xx=gcd(xx,a[i]); } if(xx>1) { cout<<"Yes"<<endl<<"0"<<endl; } else { for(int i=0;i<n-1;i++) { while(abs(a[i])%2==1) { ans++; t=a[i]; a[i]=a[i]-a[i+1]; a[i+1]=t+a[i+1]; } } while(abs(a[n-1])%2==1) { ans++; t=a[n-2]; a[n-2]=a[n-2]-a[n-1]; a[n-1]=t+a[n-1]; } if(ans) { cout<<"YES"<<endl<<ans<<endl; } else { cout<<"NO"<<-1<<endl; } } return 0; }