SDUT 2021 Winter Individual Contest - L

74 篇文章 12 订阅
48 篇文章 0 订阅

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;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值