SDUT 2021 Spring Individual Contest - C(Gym 100814)

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

A - Arcade 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-8
const int mod = 1e9 + 7;
const int MOD = 1e4+7;
const int N = 1e5 + 10;
const int M = 1111;
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;

int dp[M];

void solve(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int tot=0;
        int nn=n;
        while(nn){
            dp[tot++]=nn%10;
            nn/=10;
        }
        sort(dp,dp+tot);
        int l=0;
        int r=0;
        do{
            int pos=0;
            rep(i,0,tot-1) pos=pos*10+dp[i];
            if(pos>n) r++;
            l++;
        }while(next_permutation(dp,dp+tot));
        double zero=0.0;
        if(!r){
            printf("%.9f\n",zero);
            continue;
        }
        double ans=1.0/l;
        double res=1.0/l;
        rep(i,1,r-1){
            ans+=(1.0/l)*res;
            res=ans;
        }
        printf("%.9f\n",ans);
    }
}

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

B - Unlucky Teacher

题目链接

答案:

#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-8
const int mod = 1e9 + 7;
const int MOD = 1e4+7;
const int N = 1e5 + 10;
const int M = 1111;
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;

int s[M][5];

void solve(){
    int t;
    scanf("%d",&t);
    while(t--){
        int n,m;
        scanf("%d %d",&n,&m);
        memset(s,-1,sizeof(s));
        char a,b;
        rep(i,1,m){
            rep(j,1,n){
                getchar();
                int k;
                scanf("%c %c",&a,&b);
                if(b=='T') k=1;
                else k=0;
                s[j][a-'A']=k;
            }
        }
        rep(i,1,n){
            int tot=0;
            int k=-1;
            int temp=-1;
            rep(j,0,3){
                if(s[i][j]==-1) tot++;
                if(s[i][j]==1)  k=j;
                if(s[i][j]==-1) temp=j;
            }
            char c;
            if(k!=-1) c=k+'A';
            else if(tot>=2) c='?';
            else c='A'+temp;
            if(i==n) cout<<c<<endl;
            else cout<<c<<" ";
        }
    }
}

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


D - Frozen Rivers

题目链接

答案:

#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f3f3f3f
#define mem(a,b) memset(a,b,sizeof(a))
#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-8
#define x first
#define y second
const int mod = 1e9 + 7;
const int MOD = 1e4+7;
const int N = 1e5 + 10;
const int M = 555;
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 next;
    ll to;
    ll val;
};

ll ans[N];
ll dist[N];
ll tot;
ll cnt;
ll head[N];
node edge[N<<1];

void add(ll u,ll v,ll w){
    edge[tot]=(node){head[u],v,w};
    head[u]=tot++;
}

void judge(ll u){
    ll minn=INF;
    for(ll i=head[u];~i;i=edge[i].next) minn=min(edge[i].val,minn);
    for(ll i=head[u];~i;i=edge[i].next){
        ll to=edge[i].to;
        if(edge[i].val==minn) dist[to]=dist[u]+edge[i].val;
        else dist[to]=dist[u]+minn+(edge[i].val-minn)*(ll)2;
        if(head[to]==-1) ans[cnt++]=dist[to];
        else judge(to);
    }
}

void solve(){
    ll t;
    cin>>t;
    while(t--){
        mem(head,-1);
        tot=0;
        cnt=0;
        ll n;
        cin>>n;
        mem(dist,0);
        rep(i,2,n){
            ll u,w;
            cin>>u>>w;
            add(u,i,w);
        }
        judge(1);
        sort(ans,ans+cnt);
        ll q;
        cin>>q;
        while(q--){
            ll m;
            cin>>m;
            ll res=upper_bound(ans,ans+cnt,m)-ans;
            cout<<res<<endl;
        }
    }
}

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




F - Geometry

题目链接

答案:

#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-8
const int mod = 1e9 + 7;
const int MOD = 1e4+7;
const int N = 1e5 + 10;
const int M = 1111;
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--){
        ll a,b;
        cin>>a>>b;
        if(a==b) cout<<"Square"<<endl;
        else cout<<"Rectangle"<<endl;
    }
}

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


I - Salem

题目链接

答案:

#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-8
const int mod = 1e9 + 7;
const int MOD = 1e4+7;
const int N = 1e5 + 10;
const int M = 1111;
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;

int dp[M];

void solve(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        rep(i,1,n) cin>>dp[i];
        int maxn=-1;
        rep(i,1,n){
            rep(j,i+1,n){
                int tot=0;
                rep(k,0,17){
                    if(((dp[i]>>k)&1)!=((dp[j]>>k)&1)) tot++;
                }
                maxn=max(maxn,tot);
            }
        }
        cout<<maxn<<endl;
    }
}

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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值