SDUT 2021 Spring Individual Contest - J (计蒜客)题解

48 篇文章 0 订阅
1 篇文章 0 订阅

A - Architecture

题目链接

答案

#include <bits/stdc++.h>

#include <algorithm>
#include <iostream>
#define ll long long
#define mem(a, b) memset(a, b, sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#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 x first
#define y second
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 1e6 + 10;
const int M = 111;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
using namespace std;

int a[N];
int b[N];

void solve() {
    int n, m;
    cin >> n >> m;
    int ma = -1;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        ma = max(ma, a[i]);
    }
    int mb = -1;
    for (int i = 1; i <= m; i++) {
        cin >> b[i];
        mb = max(mb, b[i]);
    }
    bool flag=0;
    for(int i=1;i<=m;i++){
        if(ma==b[i]) flag=1;
        if(ma<b[i]){
            cout << "impossible" << endl;
            return ;
        }
    }
    if (flag)
        cout << "possible" << endl;
    else
        cout << "impossible" << endl;
}

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

B - Bracket Sequence

题目链接

答案

#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#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 x first
#define y second
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;

void solve(){
    int n;
    cin >> n;
    string s;
    int tot = 0;
    stack<ll> st;
    for (int i = 0; i < n; i++) {
        cin >> s;
        if (s[0] == '(') {
            st.push(-1);
            tot++;
        } else if (s[0] ==')') { 
            if (tot & 1) {
                ll res = 1;
                while (st.top() != -1){
                    res = (res * st.top()) % MOD;
                    st.pop();
                }
                st.pop();
                st.push(res);
            } else {
                ll res = 0;
                while (st.top() != -1){
                    res = (res + st.top()) % MOD;
                    st.pop();
                }
                st.pop();
                st.push(res);
            }
            tot--;
        } else {
            ll num = 0;
            for (int j = 0; j < (int)s.size(); j++) 
                num = num * 10 + s[j] - '0';
            st.push(num);
        }
    }
    ll ans = 0;
    while (!st.empty()) {
        ans = (ans + st.top()) % MOD;
        st.pop();
    }
    cout << ans << endl;
}

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

D - Deceptive Dice

题目链接

答案

#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#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 x first
#define y second
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;

ll num[N];

void solve(){
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        num[i]=num[i-1]+i;
    }
    double temp=num[n]*1.0/n;
    ll res,pos;
    for(int i=2;i<=k;i++){
    //    res=ceil(temp);
    //    pos=floor(temp);
       res= (ll) temp;
       temp=(num[n]-num[res])*1.0/n+res*temp/n;
    }
    cout<<fixed<<setprecision(8)<<temp<<endl;
}

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

F - Floor Plan

题目链接

答案

#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#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 x first
#define y second
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 1e6 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;

void solve(){
    ll n;
    cin >> n;
    if (n & 1) {
        cout << n / 2 + 1 << " " << n / 2;
    } else {
        if (n % 4) {
            cout << "impossible";
        } else {
            cout << (n / 2 + 2) / 2 << " " << (n / 2 - 2) / 2;
        }
    }
}

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

G - Greetings!

题目链接

答案

#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#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 x first
#define y second
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;

void solve(){
    string s;
    cin>>s;
    int len=s.size();
    len-=2;
    len*=2;
    cout<<"h";
    for(int i=1;i<=len;i++) cout<<"e";
    cout<<"y"<<endl;
}

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

I - Inquiry I

题目链接

答案

#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#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 x first
#define y second
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 1e6 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;

int dp[N];

void solve(){
    int n;
    cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++){
        cin>>dp[i];
        sum+=dp[i];
    }
    ll maxn=-1;
    ll col=0;
    for(int i=1;i<=n;i++){
        col+=dp[i]*dp[i];
        sum-=dp[i];
        ll res=col*sum;
        maxn=max(maxn,res);
    }
    cout<<maxn<<endl;
}

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

H - Hexagonal Rooks(补)

题目链接

答案

#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#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 x first
#define y second
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;

string a, b;
int dp[]={6,7,8,9,10,11,10,9,8,7,6};

int get(string s){
    int num=0;
    for(int i=1;i<(int)s.size();i++){
        num=num*10+s[i]-'0';
    }
    return num;
}

bool judge(int s,int st,int e,int et){
    if(e==s) return 1;
    if(s>='f') st+=s-'f';
    if(e>='f') et+=e-'f';
    if(st==et) return 1;
    if(st-et==s-e) return 1;
    else return 0;
}

void solve(){
    cin>>a>>b;
    int s=a[0];
    int e=b[0];
    int st=get(a);
    int et=get(b);
    int res=0;
    for(int i='a';i<='k';i++){
        int p=dp[i-'a'];
        for(int j=1;j<=11;j++){
            if(j>p) break;
            if((s==i&&st==j)||(e==i&&et==j)) continue;
            if(judge(s,st,i,j)&&judge(i,j,e,et)) res++;
        }
    }
    cout<<res<<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、付费专栏及课程。

余额充值