首页 > 其他分享 >SMU Spring 2023 Contest Round 3(2023年湘潭大学新生赛)

SMU Spring 2023 Contest Round 3(2023年湘潭大学新生赛)

时间:2023-05-14 13:45:02浏览次数:40  
标签:cout Contest int Spring 2023 long ++ solve ans

Problem A. 签到啦

从大到小排序,累加大于行李w时输出下标即可

int ans;
void solve()
{
    cin >> n >> m;
    int ans = 0;
    vector<int> a(n);
    for(int i = 0;i < n;i ++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    reverse(a.begin(),a.end());
    for(int i = 0;i < n; i++ ){
        ans += a[i];
        if(ans >= m){
            cout << i + 1 << endl;
            return;
        }
    }
}

 

 Problem B. 熙巨打票

冷却时间小于操作时间时,实际上就等于操作时间乘以票数,大于操作时间时,假设操作时间4分钟,冷却时间10分钟,在两台上操作完后还需要等6分钟才能进行操作,6分钟后第一台操作完毕后刚好10分钟这时第二台有可以操作了,如此往复,票数是奇数时除以就是要等待的次数,偶数时需减一次,因为最后一次出完后不需要再等待了.

void solve() {
   int a,b,n;
   cin >> a >> b >> n;
   if(a <= b){
       cout << b * n << endl;
       return ;
   }
   else{
       if(n & 1){
           cout << b * n + (n>>1) * (a - b) << endl;
       }
       else{
           cout << b * n + ((n >> 1) - 1) * (a - b) << endl;
       }
   }
}

 

 Problem C. 三元分配

按题意我们可以先分成四种情况,即(以下奇数简称奇,偶数简称偶)奇奇奇,奇奇偶,奇偶偶,偶偶偶,其中奇奇奇和奇偶偶一定是不能配对的,偶偶偶是一定可以配对,所以我们要对奇奇偶这种情况再讨论,因为两个部门要凑成质数才可以进行配对,而两个奇数加起来是质数只能是两个1,且两个1加一个偶数是一定可以配对的,另外再讨论两个奇数与偶数配对成质数的情况即可,当偶数是0时,这时就变成了两个奇数配对了,此时要特判一下

 

 

 

 

bool f(int x){
    if(x < 2)
        return false;
    if(x == 2)
        return true;
    for(int i = 2;i <= sqrt(x);i ++)
        if(x % i == 0)
            return false;
    return true;
}
void solve()
{
    cin >> n >> m >> k;
    if((n + m + k) & 1){
        cout << 'P' << endl;
        return ;
    }
    if(n % 2 == 0 && m % 2 == 0 && k % 2 == 0){
        cout << 'R' << endl;
        return ;
    }
    if(n == 1 && m == 1 || n == 1 && k == 1 || m == 1 && k == 1){
        cout << 'R' << endl;
        return ;
    }
    if(f(n + m) && f(n + k) &&n != 0 || f(m + n) && f(m + k) && m != 0 || f(k + n) && f(k + m) && k != 0){
        cout << 'R' << endl;
        return ;
    }
    cout << 'P' << endl;
    return ;
}

 

Problem D. "逆"天求和

哎,还特意查了一下逆元的公式啥的,最后发现这道题要做的话感觉又和逆元没啥关系

 

感兴趣的可以自己推到一下,就是说当p为质数时,其1到p-1的逆元都在1到p-1中且互不重复

所以我们直接1到p-1累加即可

void solve()
{
    cin >> n;
    int sum = 0;
    for(int i = 1;i < n;i ++){
        sum += i; 
    } 
    cout << sum << endl;
}

 

 

Problem E. 读中国数字

纯模拟,不想多说(

 

#include  <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define endl '\n'
#define int long long

using namespace std;

const int N = 1e5 + 10, mod = 1e9 +7;

//typedef long long ll;
typedef pair<int,int> PII;
//queue<PII> q1;
//priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t,k;
/*
*/
int ans;
void solve()
{
    string num;
    cin >> num;
    if(num == "0"){
        cout << num << endl;
        return ;
    }
    string chinese = "";
    string unit[] = {"", "T", "B", "K", "W", "Y"};
    string digit[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
    int len = num.length();
    int i = 0;
    while (i < len) {
        int j = len - i - 1;
        int k = j % 4;
        bool fw = false,fy = false;
        if (num[i] == '0') {
            int zeroCount = 0;
            bool f = false;
            while (i < len && num[i] == '0') {
                i++;
                if((len - i) == 8 && !fy){
                    chinese += "Y";
                    f = true;
                    fy = true;
                }
                if((len - i) == 4 && !f && !fw && chinese.back() != 'Y'){
                    chinese += "W";
                    f = true;
                    fw = true;
                }
                zeroCount++;
            }
            if (j == 4 && !f && !fw) {
                chinese += "W";
            } else if (j == 8 && !f && !fy) {
                chinese += "Y";
            }
            if(zeroCount >= 1 && i != len && (len - i) != 4 && (len - i) != 8)
                chinese += '0';
        } else {
            chinese += digit[num[i] - '0'] + unit[k];
            if (j == 4 && !fw) {
                chinese += "W";
                fw = true;
            } else if (j == 8 && !fy) {
                chinese += "Y";
                fy = true;
            }
            i++;
        }
    }
    cout << chinese << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int Ke_scholar = 1;
    cin >> Ke_scholar ;
    while(Ke_scholar--)
        solve();
    return 0;
}

 

 Problem H. 我爱XTU

可以每次计算x,t,u的数量,用pair对其中两个的差进行一个存储,如果这个pair前面出现过,说明从前面到现在有加了x,t,u数量相同的子串,需要注意的当x,t,u数量相等的时候需要加一次,或者在最开始就往pair对里放一组{0,0}.

 

#include  <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define endl '\n'
#define int long long

using namespace std;

const int N = 1e5 + 10, mod = 1e9 +7;

//typedef long long ll;
typedef pair<int,int> PII;
//queue<PII> q1;
//priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t,k;
/*
*/
int ans;
void solve()
{
    string s;
    cin >> s;
    ans = 0;
    int x = 0, t = 0, u = 0;
    map<PII, int> mp;
    for(int i = 0;i < s.size();i ++){
        if(s[i] == 'X')
            x ++;
        else if(s[i] == 'T')
            t ++;
        else
            u ++;
        int divx = x - t;
        int divu = u - t;
        if(x == t && t == u)
            ans ++;
        if(mp.count({divx,divu})){
            ans += mp[{divx, divu}];
           // cout << x << ' ' << t << ' ' << u << endl;
        }
        mp[{divx,divu}]++;
    }
    cout << ans << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int Ke_scholar = 1;
    cin >> Ke_scholar ;
    while(Ke_scholar--)
        solve();
    return 0;
}

 

标签:cout,Contest,int,Spring,2023,long,++,solve,ans
From: https://www.cnblogs.com/Kescholar/p/17399126.html

相关文章

  • 2023 SMU RoboCom-CAIP 选拔赛
    A.小斧头  #include<map>#include<set>#include<cmath>#include<queue>#include<stack>#include<cstdio>#include<vector>#include<climits>#include<cstring>#include<cstdlib>......
  • SMU Spring 2023 Contest Round 1
    B.ContestPreparation#include<iostream>#include<cstdio>#include<algorithm>#include<string>#include<cstring>#include<vector>#include<queue>#include<set>#include<map>#defineinf0x3f......
  • SMU Spring 2023 Contest Round 2
    M.DifferentBilling#include<map>#include<set>#include<cmath>#include<queue>#include<cstdio>#include<vector>#include<climits>#include<cstring>#include<cstdlib>#include<......
  • 2023-05-14 leetcode竞赛
    6430. 找出转圈游戏输家mysolution100%passclassSolution:defcircularGameLosers(self,n:int,k:int)->List[int]:seen=set()now_num=1step=1seen.add(1)while1:stepSum=step*ktotal=......
  • maven创建springboot项目
    创建maven项目,pom.xml文件如下:<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation=&......
  • Spring Boot 1.5.x 结合 JUnit5 进行接口测试
    在SpringBoot1.5.x中,默认使用Junit4进行测试。而在对Controller进行接口测试的时候,使用@AutoConfigureMockMvc注解是不能注入MockMvc对象的。因此只能使用WebApplicationContext类去构建MockMvc对象。在SpringBoot1.5.x+Junit4的前提下,测试类的代码是这样写的:@Sp......
  • Java:SpringBoot整合MyBatis-Plus实现MySQL数据库的增删改查
    MyBatis-Plus(简称MP)是一个MyBatis的增强工具,在MyBatis的基础上只做增强不做改变,为简化开发、提高效率而生。文档https://baomidou.com/目录一、引入坐标二、配置三、CURD测试四、API数据接口一、引入坐标<dependency><groupId>com.baomidou</groupId><artifactId>m......
  • 蓝桥杯 2023 省 A 网络稳定性
    蓝桥杯撞题NOIP原题,做法也一模一样(撞题:NOIP2013提高组货车运输)由题意可得这是让我们先求一个最大生成树(把求最小生成树反过来求即可),再求最小边权。求最大生成树我们可以用并查集+排序做出。求最小边权我们可以LCA,也可以树链剖分+线段树维护。后者码量太大(本人太懒),没打算写。......
  • NOC 2023 知识点
    NOC2023知识点1.函数的定义1.1函数的名字只能是数字、字母或下划线,不可以用数字开头(int2abc是非法的),不可以使用关键字名称(intchar是非法的)。1.2函数可以嵌套调用,但是不可以嵌套定义。如下例。intfun1(){...}intfun2(){func1();//合法...}i......
  • 大公司为什么禁止SpringBoot项目使用Tomcat?
    前言在SpringBoot框架中,我们使用最多的是Tomcat,这是SpringBoot默认的容器技术,而且是内嵌式的Tomcat。同时,SpringBoot也支持Undertow容器,我们可以很方便的用Undertow替换Tomcat,而Undertow的性能和内存使用方面都优于Tomcat,那我们如何使用Undertow技术呢?本文将为大家细细讲解。Spr......