SDUT 2021 Winter Individual Contest - J(Gym-101879)

48 篇文章 0 订阅
34 篇文章 0 订阅

B - Aesthetics in poetry

题目链接

答案

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#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 N = 1e5 + 10;
const int M = 211;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;

ll dp[N];
int vis[N];

bool judge(int n,ll key){
    if(n%key) return 0;
    memset(vis,0,sizeof(vis));
    rep(i,1,n) vis[dp[i]%key]++;
    rep(i,0,key-1){
        if(vis[i]!=n/key) return 0;
    }
    return 1;
}

void solve(){
    int n;
    cin>>n;
    rep(i,1,n) cin>>dp[i];
    ll res;
    bool flag=0;
    for(ll i=2;i<=n;i++){
        if(judge(n,i)){
            res=i;
            flag=1;
            break;
        }
    }
    if(flag) cout<<res<<endl;
    else cout<<-1<<endl;
}

int main() {
    solve();
	return 0;
}

D - Maximizing Advertising

题目链接

答案

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#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 N = 1e6 + 10;
const int M = 211;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;

struct node{
    int x;
    int y;
    int sum;
}dp[N];

int tot;
int cnt;

bool cmp(node x,node y){
    if(x.x<y.x) return 1;
    else if(x.x==y.x&&x.y<y.y) return 1;
    return 0;
}

bool bmp(node x,node y){
    if(x.y<y.y) return 1;
    else if(x.y==y.y&&x.x<y.x) return 1;
    return 0;
}

void solve(){
    int n;
    cin>>n;
    string s;
    rep(i,1,n){
        cin>>dp[i].x>>dp[i].y>>s;
        if(s[0]=='b'){
            dp[i].sum=0;
            tot++;
        }
        else{
            dp[i].sum=1;
            cnt++;
        }
    }
    sort(dp+1,dp+1+n,cmp);
    int b=tot;
    int w=cnt;
    int sumb=0;
    int sumw=0;
    int maxn=max(b,w);
    rep(i,1,n){
        if(!dp[i].sum) b--,sumb++;
        else w--,sumw++;
        maxn=max(maxn,max(b+sumw,w+sumb));
    }
    sort(dp+1,dp+1+n,bmp);
    b=tot;
    w=cnt;
    sumb=0;
    sumw=0;
    //maxn=max(b,w);
    rep(i,1,n){
        if(!dp[i].sum) b--,sumb++;
        else w--,sumw++;
        maxn=max(maxn,max(b+sumw,w+sumb));
    }
    cout<<maxn<<endl;
}

int main() {
    solve();
	return 0;
}

E - Group work

题目链接

题意

给定n个人,问组队种类的最多数量
组队要求:

  1. 每队大于等于两人
  2. 队伍中有一人不同就算不同队伍

思路

n个元素的集合,元素数量大于1的真子集数目

答案

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#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 N = 1e6 + 10;
const int M = 211;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;

void solve(){
    int n;
    cin>>n;
    int tot=1;
    rep(i,0,n-1) tot*=2;
    tot-=n+1;
    cout<<tot<<endl;
}

int main() {
    solve();
	return 0;
}

G - Running a penitentiary

题目链接

答案

#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 N = 1e6 + 10;
const int M = 211;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;

int n,m;
int dp[N];
int mp[N];
int st1[N];
int st2[N];

void up1(int k){
    while(k<=n){
        st1[k]=dp[k];
        for(int i=1;i<(lowbit(k));i<<=1) st1[k]=max(st1[k],st1[k-i]);
        k+=lowbit(k);
    }
}

void up2(int k){
    while(k<=n){
        st2[k]=mp[k];
        for(int i=1;i<(lowbit(k));i<<=1) st2[k]=max(st2[k],st2[k-i]);
        k+=lowbit(k);
    }
}

int que1(int l,int r){
    int res=-INF;
    while(l<=r){
        res=max(res,dp[r]);
        for(--r;l<=r-(lowbit(r));r-=lowbit(r)) res=max(res,st1[r]);
    }
    return res;
}

int que2(int l,int r){
    int res=-INF;
    while(l<=r){
        res=max(res,mp[r]);
        for(--r;l<=r-(lowbit(r));r-=lowbit(r)) res=max(res,st2[r]);
    }
    return -res;
}

void solve(){
    cin>>n>>m;
    rep(i,1,n){
        cin>>dp[i]>>mp[i];
        mp[i]=-mp[i];
        up1(i);
        up2(i);
    }
    while(m--){
        int l,r;
        string ope;
        cin>>ope;
        if(ope[0]=='?'){
            cin>>l>>r;
            ll L=1ll*que1(l,r);
            ll R=1ll*que2(l,r);
            if(L>R) puts("0");
            else cout<<R-L+1<<endl;
        }
        else{
            int pos;
            cin>>pos>>l>>r;
            dp[pos]=l;
            mp[pos]=-r;
            up1(pos);
            up2(pos);
        }
    }
}

int main() {
    solve();
	return 0;
}

I - A story about tea

题目链接

答案

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#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 N = 1e5 + 10;
const int M = 211;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;

int tot;

void hanno(int n,char a,char b,char c){
    if(n==0) return ;
    hanno(n-1,a,c,b);
    if(tot&&n==1){
        cout<<a<<" "<<b<<endl;
        cout<<b<<" "<<c<<endl;
        tot=0;
    }
    else cout<<a<<" "<<c<<endl;
    hanno(n-1,b,a,c);
}

void solve(){
    int n,k;
    cin>>n>>k;
    tot=k-(1<<n)+1;
    if(tot<0){
        puts("N");
        return ;
    }
    else{
        puts("Y");
        while(tot>=2){
            puts("A B");
            puts("B A");
            tot-=2;
        }
    }
    hanno(n,'A','B','C');
}

int main() {
    solve();
	return 0;
}

J - Meme Wars

题目链接

答案

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#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 N = 1e6 + 10;
const int M = 211;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;

void solve(){
    int n;
    cin>>n;
    int tot=0;
    while(n%2==0){
        tot++;
        n/=2;
    }
    char s=tot+'a';
    cout<<s<<endl;
}

int main() {
    solve();
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值