其他分享
首页 > 其他分享> > 2020年西安电子科技大学新生赛现场赛代码

2020年西安电子科技大学新生赛现场赛代码

作者:互联网

#include<stdio.h>
#include<algorithm>
using namespace std;
#define M 100005
int A[M],n;
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&A[i]);
	sort(A,A+n);
	printf("Bogosort:");
	for(int i=n-1;i>=0;i--)
		printf(" %d",A[i]);
	puts("");
	return 0;
}
#include<bits/stdc++.h>
#define M 100005
#define LL long long
using namespace std;
struct node{LL x,y;}A[M],sum;
int n,cnt;
bool check(){
	for(int i=1;i<=n;i++){
		node tmp;tmp.x=sum.x-A[i].x;tmp.y=sum.y-A[i].y;
		if(tmp.x*tmp.x+tmp.y*tmp.y==A[i].x*A[i].x+A[i].y*A[i].y)
			return 1;
		if(tmp.x==0&&tmp.y==0)return 1;
		if(!(A[i].x==0&&A[i].y==0)&&tmp.y*A[i].x==A[i].y*tmp.x)return 1;
	}
	return 0;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld%lld",&A[i].x,&A[i].y);
		sum.x+=A[i].x;
		sum.y+=A[i].y;
	}
	if(check())puts("yes");
	else puts("no");
	return 0;
}
#include<bits/stdc++.h>
#define LL long long
#define M 1000005
using namespace std;
LL n;
int pri[M];bool mark[M];
void Init(){
	for(int i=2;i<M;i++){
		if(!mark[i])pri[++pri[0]]=i;
		for(int j=i+i;j<M;j+=i)
			mark[j]=1;
	}
}
int main(){
	Init();
	scanf("%lld",&n);
	LL ans=1;
	for(int i=1;i<=pri[0];i++){
		if(n%pri[i]==0)
			ans*=pri[i];
		while(n%pri[i]==0)n/=pri[i];
	}
	printf("%lld\n",n*ans);
	return 0;
}
#include<bits/stdc++.h>
#define M 100005
using namespace std;
int n,D,in[M];
int main(){
    scanf("%d%d",&n,&D);
    for(int i=1,a,b;i<n;i++){
        scanf("%d%d",&a,&b);
        in[a]++;in[b]++;
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        if(in[i]>D){
            int res=(in[i]-D)/(D-2);
            if((in[i]-D)%(D-2)!=0)res++;
            if(res<0)res=0;
            ans+=res;
        }
    }
    printf("%d\n",ans);
    return 0;
}
#include<bits/stdc++.h>
#define M 100005
using namespace std;
int n,T,t;
int main(){
    cin>>T;
    while(T--){
        scanf("%d%d",&n,&t);
        if(n==1)puts(":-)");
        else if(t==1){
            if(n%2==0)puts(":-(");
            else puts(":-)");
        }
        else puts(":-(");
    }
    return 0;
}
#include<bits/stdc++.h>
#define M 100005
using namespace std;
int n,cur=1;
char S[M],mx[M];
int main(){
	scanf("%d%s",&n,S+1);
	for(int i=1;i<=n;i++)mx[i]=max(mx[i-1],S[i]);
	for(int i=2;i<n;i++)
		if(S[i]<mx[cur])cur=i;
	sort(S+1,S+cur+1);
	sort(S+cur+1,S+n+1);
	puts(S+1);
	return 0;
}
#include<bits/stdc++.h>
#pragma GCC optimize(2)
#define LL long long
#define M 400005
using namespace std;
int n;
LL mv,l;
map<int,int>mp;
map<int,int>::iterator it;
int main(){
	scanf("%lld%d",&l,&n);
	while(n--){
		int op;LL x;
		scanf("%d%lld",&op,&x);
		if(op==1){
			x-=mv;x=(x%l+l)%l;
			mp[x]++;
		}
		else if(op==2){
			x-=mv;x=(x%l+l)%l;mp[x]--;
			if(mp[x]==0)mp.erase(x);
		}
		else if(op==3)mv+=x;
		else {
			LL a,b;x-=mv;x=(x%l+l)%l;
			it=mp.lower_bound(x);
			if(it!=mp.end())a=it->first;
			else a=mp.begin()->first;
			if(it!=mp.begin()){it--;b=it->first;}
			else {it=mp.end();it--;b=it->first;}
			x+=mv;x=(x+l)%l;a=(a+mv)%l;b=(b+mv)%l;
			if(a>b)swap(a,b);if(min(l-abs(a-x),abs(a-x))>min(l-abs(b-x),abs(b-x)))swap(a,b);
			printf("%lld\n",a);
		}
	}
	return 0;
}
#include<bits/stdc++.h>
#define LL long long
#define M 35
using namespace std;
const int mod=1e9+7;
int n,m,cnt[M];
bool G[M][M];
bool vis[M];
void dfs(int x){
    cnt[x]++;vis[x]=1;
    for(int i=1;i<=n;i++)
        if(G[x][i]&&!vis[i])dfs(i);
}
LL Ans;
LL qkpow(LL a,LL b){
    LL ans=1;
    while(b){
        if(b&1)ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}
int main(){
    cin>>n>>m;
    for(int i=1,a,b;i<=m;i++){
        scanf("%d%d",&a,&b);
        G[a][b]=1;
    }
    for(int i=1;i<=n;i++){
        memset(vis,0,sizeof(vis));
        dfs(i);
    }
    for(int i=1;i<=n;i++)
        Ans=(Ans+qkpow(cnt[i],mod-2))%mod;
    printf("%lld\n",Ans);
    return 0;
}

标签:int,LL,西安电子科技大学,namespace,新生,2020,mp,include,define
来源: https://www.cnblogs.com/zeroy/p/15610035.html