第十五届中北大学算法与程序设计竞赛(公开赛)题解
B.真的是签到题
题意:
题解:
AC代码
/* Author:zzugzx Lang:C++ Blog:blog.csdn.net/qq_43756519 */ #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; //const int mod=1e9+7; const int mod=998244353; const double eps = 1e-10; const double pi=acos(-1.0); const int maxn=1e6+10; const ll inf=0x3f3f3f3f; const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}}; int main() { //ios::sync_with_stdio(false); //cin.tie(0);cout.tie(0); //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); puts("NUC2020!!!"); puts("NUC2020!!!"); puts("NUC2020!!!"); return 0; }
A.俄罗斯方块
题意:
题解:
AC代码
/* Author:zzugzx Lang:C++ Blog:blog.csdn.net/qq_43756519 */ #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; //const int mod=1e9+7; const int mod=998244353; const double eps = 1e-10; const double pi=acos(-1.0); const int maxn=1e6+10; const ll inf=0x3f3f3f3f; const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}}; int a[20][20]; int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int n; cin>>n; for(int i=1,x,y;i<=n;i++){ cin>>y>>x; if(y==1){ int z=1; while(!a[z+1][x]&&!a[z+1][x+1]&&z<10)z++; a[z][x]=a[z-1][x]=a[z][x+1]=a[z-1][x+1]=1; } else if(y==2){ int z=1; while(!a[z+1][x]&&!a[z+1][x+1]&&!a[z+1][x+2]&&z<10)z++; a[z][x]=a[z][x+1]=a[z][x+2]=a[z-1][x]=1; } else if(y==3){ int z=1; while(!a[z+1][x]&&!a[z+1][x+1]&&!a[z+1][x+2]&&!a[z+1][x+3]&&z<10)z++; a[z][x]=a[z][x+1]=a[z][x+2]=a[z][x+3]=1; } else{ int z=1; while(!a[z+1][x]&&!a[z+1][x+1]&&!a[z+1][x+2]&&z<10)z++; a[z][x]=a[z][x+1]=a[z][x+2]=a[z-1][x+1]=1; } } for(int i=1;i<=10;i++,cout<<endl) for(int j=1;j<=10;j++) cout<<a[i][j]<<' '; return 0; }
K.签个到
题意:
题解:
AC代码
/* Author:zzugzx Lang:C++ Blog:blog.csdn.net/qq_43756519 */ #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; //const int mod=1e9+7; const int mod=998244353; const double eps = 1e-10; const double pi=acos(-1.0); const int maxn=1e6+10; const ll inf=0x3f3f3f3f; const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}}; ll a[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); ll n,m;cin>>n>>m; ll mi=inf,mx=-inf; for(int i=1;i<=n;i++)cin>>a[i],mi=min(mi,a[i]),mx=max(mx,a[i]); if(n==1){cout<<0;return 0;} ll ans=0; for(int i=1;i<=n;i++){ ll k=max(abs(a[i]-mi),abs(a[i]-mx)); ans=max(ans,k+i*m); } cout<<ans; return 0; }
E.简单的线性代数
题意:
题解:
AC代码
/* Author:zzugzx Lang:C++ Blog:blog.csdn.net/qq_43756519 */ #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; //const int mod=1e9+7; const int mod=998244353; const double eps = 1e-10; const double pi=acos(-1.0); const int maxn=1e6+10; const ll inf=0x3f3f3f3f; const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}}; ll a[1010][1010]; int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); ll n,k;cin>>n>>k; for(int i=1;i<=n;i++,cout<<endl) for(int j=1;j<=n;j++) { ll x; cin>>x; if(i==j)cout<<1ll-x<<' '; else cout<<-x<<' '; } return 0; }
G. 数位操作1
题意:
题解:
AC代码
/* Author:zzugzx Lang:C++ Blog:blog.csdn.net/qq_43756519 */ #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; //const int mod=1e9+7; const int mod=998244353; const double eps = 1e-10; const double pi=acos(-1.0); const int maxn=1e6+10; const ll inf=0x3f3f3f3f; const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}}; int cnt[10]; int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); ll n; while(cin>>n){ vector<int> v; if(n<10){cout<<1<<n<<endl;continue;} for(int i=9;i>1;i--) while(n%i==0)v.pb(i),n/=i; if(n>9){cout<<-1<<endl;continue;} reverse(all(v)); for(auto i:v)cout<<i; cout<<endl; } return 0; }
C. 港口
题意:
题解:
原题链接
AC代码
/* Author:zzugzx Lang:C++ Blog:blog.csdn.net/qq_43756519 */ #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; //const int mod=1e9+7; const int mod=998244353; const double eps = 1e-10; const double pi=acos(-1.0); const int maxn=1e6+10; const ll inf=0x3f3f3f3f; const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}}; ll b[maxn],a[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int n; cin>>n; for(int i=1;i<=n;i++)cin>>a[i]; ll x=0,y=0; for(int i=1;i<=n;i++)b[i]=a[i]-a[i-1]; for(int i=2;i<=n;i++){ if(b[i]<0)y+=-b[i]; else x+=b[i]; } cout<<max(x,y); return 0; }
F. 集合操作
题意:
题解:
AC代码
/* Author:zzugzx Lang:C++ Blog:blog.csdn.net/qq_43756519 */ #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define endl '\n' typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; //const int mod=1e9+7; const int mod=998244353; const double eps = 1e-10; const double pi=acos(-1.0); const int maxn=2e6+10; const ll inf=0x3f3f3f3f; const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}}; struct node{ int id,x; }p[maxn]; int a[maxn],c[maxn]; int lowbit(int x){ return x&(-x); } void add(int x,int v){ while(x<maxn){ c[x]+=v; x+=lowbit(x); } } int query(int x){ int res=0; while(x){ res+=c[x]; x-=lowbit(x); } return res; } int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int n;cin>>n; for(int i=1;i<=n;i++) cin>>p[i].id>>p[i].x,a[2*i-1]=p[i].x,a[2*i]=p[i].x+1; int len=2*n; sort(a+1,a+1+len); len=unique(a+1,a+1+len)-a-1; for(int i=1;i<=n;i++){ int op=p[i].id; int x=lower_bound(a+1,a+1+len,p[i].x)-a; if(op==1){ if(!(query(x)-query(x-1)))add(x,1); } if(op==2){ if(query(x)-query(x-1))add(x,-1); } if(op==3){ int l=x,r=len,ans=-1; while(l<=r){ int mid=l+r>>1; if(query(mid)-query(x-1)>=mid-x+1)ans=mid,l=mid+1; else r=mid-1; } if(ans!=-1)cout<<a[ans]+1<<endl; else cout<<a[x]<<endl; } } return 0; }