• 微信公众号:美女很有趣。 工作之余,放松一下,关注即送10G+美女照片!

SDUT 2021 Winter Individual Contest – L

互联网 diligentman 3周前 (02-18) 6次浏览

题目

  • B – Super Mancunian
  • C – Parity Game
  • F – Combo Meal
  • G – Maximum Palindromes
  • H – Constructing a Number
  • J – Halloween Sale
  • E – Cloudy Day(补)

B – Super Mancunian

题目链接

答案:

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eps 1e-6
const int mod = 1e9 + 7;
const int MOD = 1e4+7;
const int N = 1e6 + 10;
const int M = 65;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
int dxy[][2]={{0,1},{1,0},{1,1},{-1,1}};
using namespace std;

struct node{
    ll u;
    ll v;
    ll w;
}dp[N];

int n,m;
int vis[N];

void init(){
    rep(i,1,n) vis[i]=i;
}

bool cmp(node x,node y){
    return x.w<y.w;
}

int Find(int k){
    if(k!=vis[k]) vis[k]=Find(vis[k]);
    return vis[k];
}

void solve(){
    cin>>n>>m;
    rep(i,1,m) cin>>dp[i].u>>dp[i].v>>dp[i].w;
    init();
    sort(dp+1,dp+1+m,cmp);
    ll maxn=-1;
    ll sum=0;
    rep(i,1,m){
        int x=Find(dp[i].u);
        int y=Find(dp[i].v);
        if(x==y) continue;
        vis[x]=y;
        sum+=dp[i].w;
        maxn=max(maxn,dp[i].w);
    }
    init();
    ll tot=0;
    rep(i,1,m){
        int x=Find(dp[i].u);
        int y=Find(dp[i].v);
        if(x==y) continue;
        if(dp[i].w>=maxn) tot++;
        else vis[x]=y;
    }
    ll res=sum-maxn;
    cout<<res<<" "<<tot<<endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
	return 0;
}

C – Parity Game

题目链接

答案:

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eps 1e-6
const int mod = 1e9 + 7;
const int MOD = 1e4+7;
const int N = 1e6 + 10;
const int M = 65;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
int dxy[][2]={{0,1},{1,0},{1,1},{-1,1}};
using namespace std;

struct node{
    ll u;
    ll v;
    ll w;
}dp[N];

int n,m;
int vis[N];

void init(){
    rep(i,1,n) vis[i]=i;
}

bool cmp(node x,node y){
    return x.w<y.w;
}

int Find(int k){
    if(k!=vis[k]) vis[k]=Find(vis[k]);
    return vis[k];
}

void solve(){
    cin>>n>>m;
    rep(i,1,m) cin>>dp[i].u>>dp[i].v>>dp[i].w;
    init();
    sort(dp+1,dp+1+m,cmp);
    ll maxn=-1;
    ll sum=0;
    rep(i,1,m){
        int x=Find(dp[i].u);
        int y=Find(dp[i].v);
        if(x==y) continue;
        vis[x]=y;
        sum+=dp[i].w;
        maxn=max(maxn,dp[i].w);
    }
    init();
    ll tot=0;
    rep(i,1,m){
        int x=Find(dp[i].u);
        int y=Find(dp[i].v);
        if(x==y) continue;
        if(dp[i].w>=maxn) tot++;
        else vis[x]=y;
    }
    ll res=sum-maxn;
    cout<<res<<" "<<tot<<endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
	return 0;
}

F – Combo Meal

题目链接

答案:

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eps 1e-6
const int mod = 1e9 + 7;
const int MOD = 1e4+7;
const int N = 1e6 + 10;
const int M = 65;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
int dxy[][2]={{0,1},{1,0},{1,1},{-1,1}};
using namespace std;

void solve(){
    int t;
    cin>>t;
    while(t--){
        int b,s,c;
        cin>>b>>s>>c;
        cout<<b+s-c<<endl;
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
	return 0;
}

G – Maximum Palindromes

题目链接

答案:

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eps 1e-6
const int mod = 1e9 + 7;
const int MOD = 1e4+7;
const int N = 2e5 + 10;
const int M = 35;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
int dxy[][2]={{0,1},{1,0},{1,1},{-1,1}};
using namespace std;

char s[N];
ll num[N][M];
ll vis[N];
ll dp[N]={1,1};
ll mp[N]={1,1};
ll vp[N]={1,1};

void init(){
    rep(i,2,N-1){
        dp[i]=dp[i-1]*i%mod;
        vp[i]=(mod-mod/i)*vp[mod%i]%mod;
        mp[i]=mp[i-1]*vp[i]%mod;
    }
}

void solve(){
    init();
    cin>>s;
    int len=strlen(s);
    rep(i,0,len-1){
        if(i){
            rep(j,0,25) num[i][j]=num[i-1][j];
        }
        num[i][s[i]-'a']++;
    }
    int q;
    cin>>q;
    int l,r;
    while(q--){
        cin>>l>>r;
        l--;
        r--;
        ll tot=0;
        ll sum=0;
        rep(i,0,25){
            vis[i]=num[r][i];
            if(l) vis[i]-=num[l-1][i];
            if(vis[i]%2) tot++;
            vis[i]/=2;
            sum+=vis[i];
        }
        ll ans=1;
        ans=ans*max(1ll,tot)%mod;
        ans=ans*dp[sum]%mod;
        rep(i,0,25){
            if(vis[i]) ans=(ans*mp[vis[i]])%mod;
        }
        cout<<ans%mod<<endl;
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
	return 0;
}

H – Constructing a Number

题目链接

答案:

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eps 1e-6
const int mod = 1e9 + 7;
const int MOD = 1e4+7;
const int N = 1e6 + 10;
const int M = 65;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
int dxy[][2]={{0,1},{1,0},{1,1},{-1,1}};
using namespace std;

void solve(){
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        ll res=0;
        rep(i,1,n){
            ll k;
            cin>>k;
            while(k){
                res+=k%10;
                res%=3;
                k/=10;
            }
        }
        if(res) puts("No");
        else puts("Yes");
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
	return 0;
}

J – Halloween Sale

题目链接

答案:

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eps 1e-6
const int mod = 1e9 + 7;
const int MOD = 1e4+7;
const int N = 1e6 + 10;
const int M = 65;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
int dxy[][2]={{0,1},{1,0},{1,1},{-1,1}};
using namespace std;

void solve(){
    int p,d,m,s;
    cin>>p>>d>>m>>s;
    int ans=0;
    for(int i=p;i>=m;i-=d){
        ans++;
        s-=i;
        if(s<0){
            s=0;
            ans--;
            break;
        }
    }
    if(s) ans+=s/m;
    cout<<ans<<endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
	return 0;
}

E – Cloudy Day(补)

题目链接

答案:

#include <bits/stdc++.h>
#define int long long
 
using namespace std;
 
const int maxn = 5e5+10;
int peoplenum[maxn],peopleid[maxn];
int pos[maxn],wid[maxn];
int people[maxn];
int n,m;
int cha[maxn];
int ans[maxn],posi,now;
int ci[maxn];
int b[maxn],cnt;
 
signed main()
{
    cin >> n;
    for ( int i=0; i<n; i++ ) {
        scanf("%lld",&peoplenum[i]);
    }
    for ( int i=0; i<n; i++ ) {
        scanf("%lld",&peopleid[i]);
        b[cnt++] = peopleid[i];
    }
    cin >> m;
    for ( int i=0; i<m; i++ ) {
        scanf("%lld",&pos[i]);
    }
    for ( int i=0; i<m; i++ ) {
        scanf("%lld",&wid[i]);
        b[cnt++] = pos[i]-wid[i];
        b[cnt++] = pos[i]+wid[i];
    }
    sort(b,b+cnt);
    cnt = unique(b,b+cnt)-b;
    for ( int i=0; i<n; i++ ) {
        int p = lower_bound(b,b+cnt,peopleid[i])-b+1;
        people[p] += peoplenum[i];
    }
    for ( int i=0; i<m; i++ ) {
        int l = lower_bound(b,b+cnt,pos[i]-wid[i])-b+1;
        int r = lower_bound(b,b+cnt,pos[i]+wid[i])-b+1;
        cha[l] += (i+1); ci[l] ++;
        cha[r+1] -= (i+1); ci[r+1]--;
    }
    int tot = 0;
    int answer = 0;
    now = 0; posi = 0;
    for ( int i=1; i<=cnt; i++ ) {
        now += cha[i];
        tot += ci[i];
        if ( tot==0 ) {
            answer += people[i];
        }
        else if ( tot==1 ) {
            ans[now] += people[i];
        }
    }
    sort(ans+1,ans+m+1,greater<int>());
    answer += ans[1];
    cout << answer << endl;
 
    return 0;
}


程序员灯塔
转载请注明原文链接:SDUT 2021 Winter Individual Contest – L
喜欢 (0)