牛客小白月赛110(代码纯享版)

目录

A.智乃办赛

B.智乃的Wordle

C.智乃的数字

D.智乃与长短期主义者博弈

E.智乃的跳跃排序

F.智乃的数组乘积


牛客小白月赛110_ACM/NOI/CSP/CCPC/ICPC算法编程高难度练习赛_牛客竞赛OJ

A.智乃办赛

 原题链接:A-智乃办赛_牛客小白月赛110

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int k=n/500;
	 n%=500;
	if(!n){
		n=500;
		k-=1;
	}
	printf("%c%03d",'A'+k,n);
}

B.智乃的Wordle

 原题链接:B-智乃的Wordle_牛客小白月赛110

#include<bits/stdc++.h>
using namespace std;
int main(){
string s,p;
cin>>s>>p;
int l[26];
for(int i=0;i<26;i++)
l[i]=0;
for(int i=0;i<8;i++)
l[s[i]-'a']++;

for(int i=0;i<8;i++){
if(s[i]==p[i])
cout<<'g';
else if(l[p[i]-'a'])
cout<<'y';
else cout<<'r';
}
cout<<endl;
if(s==p)
cout<<"congratulations";
else
cout<<"defeat";
}

C.智乃的数字

原题链接:C-智乃的数字_牛客小白月赛110

#include<bits/stdc++.h>
using namespace std;
int a[8];
int main(){
	int n;
	cin>>n;
	a[1]=3;
	a[2]=5;
	a[3]=9;
	a[4]=5;
	a[5]=1;
	a[6]=5;
	a[7]=7;	
	while(n--){
		int k;
		cin>>k;
		long long  x=k/7;
		
	
		int l=k%7;
		if(!l)
		{
		x-=1; 
		l=7;
		} 
			x*=30;
		if(l<=3){
			x+=a[l];
		}
		else if(l==4)
		x+=15;
	else{
		x+=20+a[l];
	}	
	cout<<x<<endl;
}

}

D.智乃与长短期主义者博弈

原题链接:D-智乃与长短期主义者博弈_牛客小白月赛110

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll a[1005],ip[1005];
ll xp[1005][1005],yp[1005][1005];
signed main(){
	fast;ll n;cin>>n;
	for(ll i=1;i<=n;i++)cin>>a[i];
	for(ll i=1;i<=n;i++){
		xp[i][i]=yp[i][i]=a[i];
		xp[i][i]=yp[i][i]=a[i];
		ip[i]=a[i]+ip[i-1];
	}
	for(ll len=2;len<=n;len++){
		for(ll i=1;i+len<=n+1;i++){
			ll j=i+len-1;
			if(a[i]>=a[j]){
				xp[i][j]=a[i]+ip[j]-ip[i]-yp[i+1][j];
			}else{
				xp[i][j]=a[j]+ip[j-1]-ip[i-1]-yp[i][j-1];
			}
			ll xa,xb,ya,yb;
			xa=ip[j]-ip[i];//i+1~j
			xb=ip[j-1]-ip[i-1];//i~j-1
			ya=a[i]+(xa-xp[i+1][j]);
			yb=a[j]+(xb-xp[i][j-1]);
			yp[i][j]=max(ya,yb);
		}
	}
	cout<<xp[1][n]<<" "<<ip[n]-xp[1][n];
	return 0;
}

E.智乃的跳跃排序

原题链接:E-智乃的跳跃排序_牛客小白月赛110

#include <bits/stdc++.h>
#define int long long
using namespace std;
int a[100005],b[100005],book[100005],c[100005];
signed main(){
    int n,k;cin>>n>>k;map<int,int>mp;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=min(k,n);i++){
        int cnt=0;
        for(int j=i;j<=n;j+=k)
            b[++cnt]=a[j];
        sort(b+1,b+1+cnt);
        cnt=0;
        for(int j=i;j<=n;j+=k)
            a[j]=b[++cnt];
    }
    for(int i=1;i<=n;i++)mp[a[i]]=i;
    for(int i=1;i<=n;i++)
        if(mp[a[i]]>0){
            int cnt=0;
            for(int j=a[i];mp[j]>0;j+=k){
                b[++cnt]=j;
                c[cnt]=mp[j];
                mp[j]=0;
            }
            for(int j=a[i]-k;mp[j]>0;j-=k){
                b[++cnt]=j;
                c[cnt]=mp[j];
                mp[j]=0;
            }sort(c+1,c+1+cnt);
            sort(b+1,b+1+cnt);
            for(int j=1;j<=cnt;j++)a[c[j]]=b[j];
        }
    int p=0;
    for(int i=2;i<=n;i++)if(a[i]<a[i-1])p=1;
    if(p)cout<<"No";
    else cout<<"Yes";
    return 0;
}

F.智乃的数组乘积

原题链接:F-智乃的数组乘积_牛客小白月赛110

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int n, p, x;
 
ll qpow(ll a, ll b=p-2)
{
    ll res = 1;
    for (; b; b>>=1) {
        if (b & 1) { res = res * a % p; }
        a = a * a % p;
    }
    return res;
}
 
void solve()
{
    cin >> n >> p >> x;
    vector<int> a(n);
    if (x == 0) {
        for (auto &val: a) {
            cin >> val;
            if (val == 0) { val = 1; }
        }
    } else {
        ll now = 1;
        set<int> num; num.insert(1);
        for (auto &val: a) {
            cin >> val;
            (now*=val)%=p;
            if (num.count(now*qpow(x)%p)) { val = now = 0; }
            if (now == 0) {
                num.clear();
                now = 1;
            }
            num.insert(now);
        }
    }
    for (auto val: a) { cout << val << " "; }
}
 
int main()
{
    cin.tie(nullptr)->sync_with_stdio(false);
    int t = 1;
    while (t--) { solve(); }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值