SMU Summer 2024 Contest Round 7

SMU Summer 2024 Contest Round 7

2024.7.26 9:00————11:00

过题数2/7
补题数5/7

  • Make Equal With Mod
  • Game on Ranges
  • Buy an Integer
  • String Formation
  • Bouquet
  • Permutation
  • String Cards

A - Make Equal With Mod

在这场比赛结束的五秒之后我把这题ac了,当时真的很无语
题解:
给出数组a,进行任意次操作,每次对数组a中每个数字除余一个大于等于2的数字,再赋值给a,如果最后能使数组a中所有数字相同,就输出YES,否则NO。
不难看出,如果没有1的话,每次将数组中最大的数字作为x,那么最终会得到0。如果有1又有0的话,这俩个数字无法变得一样,如果有1又有2的的话,无法通过每次将数组中最大元素的值减1作为x,使得所有数字变成1,因为2的减1无法作为x。全是1的情况也满足条件。
代码:

#include<bits/stdc++.h>

using namespace std;
#define int long long
int t;
int a[100010];

signed main() {
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        memset(a,0,sizeof a);
        bool st = true;
        bool stt = true;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            if(a[i] == 1)st = false;
            if(a[i] == 0 || a[i] == 2)stt = false;
        }
        if(!st && !stt) {
            cout << "NO" << endl;
        }
        else if(!st && stt) {
            sort(a+1,a+1+n);
            bool aaa = true;;
            for (int i = 1; i <= n-1; i++) {
                if(a[i] == 1)continue;
                if(a[i+1]-a[i] == 1)aaa = false;
            }
            if(!aaa)cout << "NO" << endl;
            else cout << "YES" << endl;
        }
        else cout << "YES" << endl;
    }
    return 0;
}

B - Game on Ranges

这题还挺简单的,当时应该先做这个
题解:
Alice有s个数字1——n,每次Alice会给出一个区间[l,r]让Bob选一个数字s,选过的s不能再选,一直到没有能选的数字为止,不需要按照顺序输出每个区间所对应的s,每个区间有唯一答案s。
从区间最短的开始往外扩,因为每个区间有唯一答案,所以最短区间一定只有一个数字,然后有俩个数字的区间,却只有一个能取,以此类推。
代码:

#include<bits/stdc++.h>

using namespace std;
#define int long long
int t;
vector<pair<int,int>>a;
bool st[1100];

bool cmp(pair<int,int>x,pair<int,int>y) {
    return x.second-x.first < y.second - y.first;
}//按照区间长度排序

signed main() {
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        memset(st,0,sizeof st);
        a.clear();
        for (int i = 0; i < n; i++) {
            int l,r;
            cin >> l >> r;
            a.push_back({l,r});
        }
        sort(a.begin(),a.end(),cmp);
        for (int i = 0; i < n; i++) {
            for (int j = a[i].first; j <= a[i].second; j++) {
                if(!st[j])cout << a[i].first << ' ' << a[i].second << ' ' << j << endl;//没有取过这个数字就输出
                st[j] = 1;
                //标记一下
            }
        }//没有超时,over
    }
    return 0;
}

C - Cake 123

这题挺莫名的,非得用二分写,你怎么不爬
题解:
给定a,b,x,商场中有1——10的9个数字,每个数字的购买需要花费an+bd(n),d(n)指n的位数,要求输出能够买的最大数字。
二分判断是否能够购买,好吧以后还是多写二分,虽然我觉得这题明明不需要二分。
代码:

#include<bits/stdc++.h>

using namespace std;
#define int long long
int a,b,x;

int js(int m) {
    int k = 0;
    while(m > 0) {
        m =m/10;
        k++;
    }
    return k;
}

signed main() {
    cin >> a >> b >> x;
    int l = 0,r = 1e9;
    while(l < r) {
        int mid = (l+r+1)/2;
        if(a*mid+b*js(mid) <= x)l =mid;
        else r = mid-1;
    }
    cout << l;
    return 0;
}

D - Multiplication Table

题解:
有一串字符串S,给出q个操作,当t=1时,翻转字符串,当t=2时,f=1就在前面加上新的字符,2就在右边加上新的字符。
这题显而易见直接暴力会操作,可以用一个st标记现在字符串是什么顺序,可以相对应的在双向队列s的俩侧加字符,最后按照st正或反输出即可。
代码:

#include<bits/stdc++.h>

using namespace std;
#define int long long
    deque<char>s;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string ss;
    cin >> ss;
    for (int i = 0; i < ss.length(); i++) {
        s.push_back(ss[i]);
    }
    int q;
    cin >> q;
    int st = 1;
    while(q--) {
        int t;
        cin >> t;
        if(t == 1) {st++;
        }
        else if(t == 2) {
            int f;
            cin >> f;
            char a;
            cin >> a;
            if(f == 1 && st%2 == 1) {
                s.push_front(a);
            }
            else if(f == 2 && st %2 == 0) {
                s.push_front(a);
            }
            else if(f == 1 && st%2 == 0) {
                s.push_back(a);
            }
            else if(f == 2 && st%2 == 1) {
                s.push_back(a);
            }
        }
    }
    if(st%2 == 1) {
        while(!s.empty()){
        cout << s.front();
        s.pop_front();}
    }
    else {
        while(!s.empty()){
            cout << s.back();
            s.pop_back();
        }
    }
    return 0;
}


E - Bouquet

题解:
Lacus
代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int p=1e9+7;
ll qmi(ll a,ll k)
{
    ll res=1;
    while(k)
    {
        if(k&1)
            res=res*a%p;
        a=a*a%p;
        k>>=1;
    }
    return res;
}
ll C(int a,int b)
{
    ll res=1;
    for(ll i=1,j=a;i<=b;i++,j--)
    {
        res=res*j%p;
        res=res*qmi(i,p-2)%p;
    }
    return res;
}
ll lucas(ll a,ll b)
{
    if(a<p&&b<p)
        return C(a,b);
    return
    C(a%p,b%p)*lucas(a/p,b/p)%p;
}
int main()
{
    ios::sync_with_stdio(false);
	ll n,a,b;
	cin>>n>>a>>b;
	cout<<(qmi(2,n)-(lucas(n,a)%p+lucas(n,b)%p)%p-1+p)%p<<endl;
}

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值