SDUT 2021 Winter Individual Contest - K(Gym-102448)

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

A - Accept or Reject

题目链接

答案:

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

int n,m;
string s;
bool flag;
int dp[N];
char str[N];

int get(string s){
    int len=s.size();
    str[0]='$';
    str[1]='#';
    int pos=2;
    rep(i,0,len-1){
        str[pos++]=s[i];
        str[pos++]='#';
    }
    str[pos]=0;
    return pos;
}

void manacher(string s){
    int len=get(s);
    int maxn=0;
    int pos=0;
    rep(i,1,len-1){
        if(i<maxn) dp[i]=min(maxn-i,dp[2*pos-i]);
        else dp[i]=1;
        while(str[i+dp[i]]==str[i-dp[i]]){
            dp[i]++;
            if(maxn<i+dp[i]){
                pos=i;
                maxn=i+dp[i];
            }
        }
    }
}

void solve(){
    //cout<<(N<<1)<<endl;
    cin>>n>>m;
    cin>>s;
    manacher(s);
    flag=0;
    int len=2*(int)s.size();
    rep(i,0,len-1){
        if(m+1<=dp[i]&&(m+1)%2==dp[i]%2) flag=1;
    }
    if(flag) puts("Accept");
    else puts("Reject");
}

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

B - Beza’s Hangover

题目链接

答案:

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

int n,m,q;
string s[N];
string str;
int vis[N];
map<string,int>mp;

void get(int k,int sum){
    for(;k<=n;k+=(lowbit(k))) vis[k]+=sum;
}

int query(int k){
    if(!k) return 0;
    int res=0;
    for(;k;k-=(lowbit(k))) res+=vis[k];
    return res;
}

void solve(){
    cin>>n>>m>>q;
    rep(i,1,n) cin>>s[i];
    rep(i,1,m){
        int k;
        cin>>str>>k;
        mp[str]=k;
    }
    rep(i,1,n) get(i,mp[s[i]]);
    while(q--){
        int k;
        cin>>k;
        if(k==1){
            int p;
            cin>>p>>str;
            int sum=query(p)-query(p-1);
            get(p,mp[str]-sum);
        }
        else{
            int l,r;
            cin>>l>>r;
            if(query(r)-query(l-1)>30*(r-l+1)) puts("YES");
            else puts("NO");
        }
    }
}

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

D - Drinking to turn red

题目链接

答案:

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

struct node{
    double d;
    int r;
}dp[N];

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

int n,x,y;

void solve(){
    cin>>n>>x>>y;
    rep(i,1,n){
        int a,b,r;
        cin>>a>>b>>r;
        ll d=(ll)(x-a)*(x-a)+(ll)(y-b)*(y-b);
        dp[i].d=sqrt(d)-r;
        dp[i].r=r;
    }
    sort(dp+1,dp+1+n,cmp);
    double st=0.0;
    double res=0.0;
    rep(i,1,n){
        if(st<dp[i].d){
            res+=dp[i].d-st;
            st+=dp[i].d-st;
        }
        st+=dp[i].r;
    }
    printf("%.10f\n",res);
}

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

E - Everybody loves acai

题目链接

不用scanf我是T了 (T^T)

答案:

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

int dp[]={6,28,496,8128};

void solve(){
    int t;
    scanf("%d",&t);
    while(t--){
        int n;
        scanf("%d",&n);
        int ans;
        if(n<dp[0]) ans=-1;
        else if(n<dp[1]) ans=dp[0];
        else if(n<dp[2]) ans=dp[1];
        else if(n<dp[3]) ans=dp[2];
        else ans=dp[3];
        printf("%d\n",ans);
    }
}
int main() {
    solve();
	return 0;
}

F - Finally, christmas!

题目链接

答案:

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

struct node{
    ll h;
    ll x;
    ll num;
}dp[N];

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

int pos;
multiset<ll>mp;

void add(ll h,ll x,ll num){
    dp[pos].h=h;
    dp[pos].x=x;
    dp[pos++].num=num;
}

void solve(){
    ll n;
    cin>>n;
    rep(i,1,n){
        int l,r,h;
        cin>>l>>r>>h;
        add(h,l,0);
        add(h,r,1);
    }
    sort(dp,dp+pos,cmp);
    mp.insert(dp[0].h);
    ll res=0;
    rep(i,1,pos-1){
        if(mp.size()){
            ll key=*(--mp.end());
            res+=key*(dp[i].x-dp[i-1].x);
        }
        if(!dp[i].num) mp.insert(dp[i].h);
        else mp.erase(mp.find(dp[i].h));
    }
    cout<<res<<endl;
}

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

G - Gorggeous Peter’s Great Friend

题目链接

答案:

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

int c,p,s;
string str;
vector<string>vp;
map<string,int> dp;
map<string,int> mp;

void solve(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>c>>p>>s;
    rep(i,0,c-1){
        cin>>str;
        vp.pb(str);
        dp[str]=0;
    }
    rep(i,0,p-1){
        int k;
        cin>>str>>k;
        mp[str]=k;
    }
    string a,b;
    rep(i,0,s-1){
        cin>>str>>a>>b;
        if(b=="AC") dp[str]+=mp[a];
    }
    vector<string>::iterator it;
    for(it=vp.begin();it!=vp.end();it++){
        cout<<*it<<" "<<dp[*it]<<endl;
    }
}
int main() {
    solve();
	return 0;
}

K - Kongey Donk

题目链接

答案:

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

int n,h;
vector<ll> dp[N];
vector<ll> mp[N];

void init(){
    rep(i,1,n){
        rep(j,1,h){
            mp[i].pb(0);
        }
    }
}

void solve(){
    cin>>n>>h;
    int k;
    rep(i,1,n){
        rep(j,1,h){
            cin>>k;
            dp[i].pb(k);
        }
    }
    init();
    rep(i,1,n) mp[i][0]=dp[i][0];
    rep(j,1,h-1){
        rep(i,1,n){
            if(i>1) mp[i][j]=max(mp[i][j],mp[i-1][j-1]+dp[i][j]);
            if(i<n) mp[i][j]=max(mp[i][j],mp[i+1][j-1]+dp[i][j]);
            mp[i][j]=max(mp[i][j],mp[i][j-1]+dp[i][j]);
        }
    }
    ll maxn=-1;
    int pos=h-1;
    rep(i,1,n) maxn=max(maxn,mp[i][pos]);
    cout<<maxn<<endl;
}

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

H - Hellcife is on fire(补)

题目链接

答案:

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

struct node{
    ll w;
    ll to;
    ll next;
}dp[N];

struct NODE{
    ll t;
    ll x;
    friend bool operator <(const NODE& a,const NODE& b){
        return a.t>b.t;
    }
};

ll n,m,k;
ll num;
ll Next[N];
ll st[N];
ll vp[N];
priority_queue<NODE>que;

void init(){
    num=0;
    memset(Next,-1,sizeof(Next));
}

void add(ll u,ll v,ll w){
    dp[num].to=v;
    dp[num].w=w;
    dp[num].next=Next[u];
    Next[u]=num++;
}

void solve(){
    init();
    cin>>n>>m>>k;
    rep(i,1,m){
        ll u,v,w;
        cin>>u>>v>>w;
        add(u,v,w);
        add(v,u,w);
    }
    rep(i,1,n){
        vp[i]=1e18;
        cin>>st[i];
    }
    rep(i,1,k){
        ll k;
        cin>>k;
        vp[k]=st[k];
        que.push(NODE{vp[k],k});
    }
    while(!que.empty()){
        ll topx=que.top().x;
        ll topt=que.top().t;
        que.pop();
        for(ll i=Next[topx];i!=-1;i=dp[i].next){
            ll to=dp[i].to;
            ll w=dp[i].w;
            if(vp[to]>topt+w+st[to]){
                vp[to]=topt+w+st[to];
                que.push(NODE{vp[to],to});
            }
        }
    }
    rep(i,1,n) cout<<vp[i]<<endl;
}

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

I - Ivan and the swimming pool(补)

题目链接

答案:

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

vector<vector<int> >v1;
vector<vector<int> >v2;

struct node{
    int x;
    int y;
};

int BFS(int x,int y,int n,int m){
    int res=1;
    v2[x][y]=0;
    queue<node>q;
    q.push((node){x,y});
    while(!q.empty()){
        node p=q.front();
        q.pop();
        rep(i,0,3){
            int xx=p.x+dxy[i][0];
            int yy=p.y+dxy[i][1];
            if(xx>0&&yy>0&&xx<=n&&yy<=m&&v2[xx][yy]>0){
                v2[xx][yy]=0;
                res++;
                q.push((node){xx,yy});
            }
        }
    }
    return res;
}

bool judge(int s,int n,int m,int d){
    rep(i,1,n){
        rep(j,1,m){
            if(v1[i][j]>=d) v2[i][j]=1;
            else v2[i][j]=0;
        }
    }
    int maxn=0;
    rep(i,1,n){
        rep(j,1,m){
            if(v2[i][j]) maxn=max(maxn,BFS(i,j,n,m));
        }
    }
    if(maxn>=s) return 1;
    else return 0;
}

void solve(){
    int s,n,m;
    cin>>s>>n>>m;
    v1.resize(n+10);
    v2.resize(n+10);
    rep(i,0,n){
        v1[i].resize(m+10);
        v2[i].resize(m+10);
    }
    int l=mod;
    int r=0;
    rep(i,1,n){
        rep(j,1,m){
            cin>>v1[i][j];
            l=min(l,v1[i][j]);
            r=max(r,v1[i][j]);
        }
    }
    l--;
    r++;
    while(r-l>1){
        int mid=(l+r)>>1;
        if(judge(s,n,m,mid)) l=mid;
        else r=mid;
    }
    cout<<l<<endl;
}

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值