首页 > 其他分享 >SMU Spring 2023 Trial Contest Round 9

SMU Spring 2023 Trial Contest Round 9

时间:2023-04-23 17:36:23浏览次数:47  
标签:typedef const Contest int Spring SMU cin long tie

SMU Spring 2023 Trial Contest Round 9

A - Wrong Subtraction

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
const int N=1e5+5,INF=0x3f3f3f3f,Mod=1e6;

const double eps=1e-6;
typedef long long ll;

int n,k;

int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>k;
    while(k--){
        int m=n%10;
        if(m)n--;
        else n/=10;
    }
    cout<<n;
    return 0;
}
View Code

 

B - Two-gram

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
const int N=1e5+5,INF=0x3f3f3f3f,Mod=1e6;

const double eps=1e-6;
typedef long long ll;

int n,ma;
string ans;
unordered_map<string,int>mp;
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n;
    string s;
    cin>>s;
    for(int i=0;i<n-1;++i){
        string a="";
        a+=s[i];
        a+=s[i+1];
        mp[a]++;
        if(mp[a]>ma){
            ma=mp[a];
            ans=a;
        }
    }
    cout<<ans;
    return 0;
}
View Code

 

C - Less or Equal

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
const int N=2e5+5,INF=0x3f3f3f3f,Mod=1e6;

const double eps=1e-6;
typedef long long ll;

int n,a[N],k;

int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>k;
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    sort(a,a+n);
    if(k==0){
        if(a[0]==1)cout<<-1;
        else cout<<1;
    }
    else{
        if(a[k-1]==a[k])cout<<-1;
        else cout<<a[k-1];
    }

    return 0;
}
View Code

 

D - Divide by three, multiply by two

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
const int N=2e2+5,INF=0x3f3f3f3f,Mod=1e6;

const double eps=1e-6;
typedef long long ll;

int n;
ll a[N],p;
unordered_map<ll,ll>mp,mm;
vector<ll>ans;
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n;
    for(int i=0;i<n;++i){
        cin>>a[i];
        mp[a[i]]++;
    }
    for(int i=0;i<n;++i){
        ll x=a[i]*2;
        if(mp[x])mm[x]=a[i];
        else if(a[i]%3==0&&mp[a[i]/3])mm[a[i]/3]=a[i];
        else p=a[i];
        
    }
    ans.push_back(p);

    for(int i=0;i<n-1;++i){
        
        ans.push_back(mm[p]);
        p=mm[p];
    }
    for(int i=n-1;i>=0;--i)cout<<ans[i]<<' ';
    return 0;
}
View Code

 

E - Cyclic Components

思路:并查集求每个连通块,若有节点的入度不为2说明不在规定的环内

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
const int N=2e5+5,INF=0x3f3f3f3f,Mod=1e6;

const double eps=1e-6;
typedef long long ll;

int n,m,fa[N],ru[N];
vector<int>ve[N];
unordered_set<int>se;
bool a[N];

int find(int x){
    if(x!=fa[x])fa[x]=find(fa[x]);
    return fa[x];
}
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;++i)fa[i]=i;
    for(int i=0,u,v;i<m;++i){
        cin>>u>>v;
        ru[u]++,ru[v]++;
        u=find(u),v=find(v);
        if(u!=v)fa[u]=v;
    }
    for(int i=1;i<=n;++i){
        int x=find(i);
        if(x==i){
            se.insert(i);
        }
        if(ru[i]!=2)a[x]=true;
    }
    int ans=0;
    for(auto v:se){
        if(!a[v])ans++;
    }
    cout<<ans;
    return 0;
}
View Code

 

 F - Consecutive Subsequence

思路:dp,f[i]状态表示:以i为结尾的集合,计算:数量最大值,f[i]=max(f[i],f[i-1]+1),由于数的范围为1e9,用map存

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>PII;
typedef pair<string,int>PSI;
const int N=2e5+5,INF=0x3f3f3f3f,Mod=1e6;

const double eps=1e-6;
typedef long long ll;

int n,cnt,p,a[N];
map<int,int>mp;
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n;
    for(int i=0;i<n;++i){
        cin>>a[i];
        mp[a[i]]=max(mp[a[i]],mp[a[i]-1]+1);
        if(mp[a[i]]>cnt){
            cnt=mp[a[i]];
            p=a[i];
        }
    }
    cout<<cnt<<'\n';
    p=p-cnt+1;
    for(int i=0;i<n;++i){
        if(a[i]==p){
            cout<<i+1<<' ';p++;
        }
    }
    return 0;
}
View Code

 

标签:typedef,const,Contest,int,Spring,SMU,cin,long,tie
From: https://www.cnblogs.com/bible-/p/17347125.html

相关文章

  • SpringBoot+React 前后端分离
    SpringBoot+React前后端分离写个转发数据的小工具,本来只想开个SpringBoot服务带个页面,但感觉有点难受,正好之前研究了React,尝试一下前后端分离。后端简单用SpringBoot起个服务,写个接口处理请求:@RestController@RequestMapping("/data")publicclassDataController{......
  • SpringIOC理论推导
    IOC理论引入原来实现业务的步骤:Dao层接口Dao层实现类Service层接口Service层实现类eg:Dao层接口publicinterfaceUserDao{voidgetUser();}Dao层实现类publicclassUserDaoImplimplementsUserDao{publicvoidgetUser(){System.ou......
  • 基于SpringBoot+Vue的音乐网站
    本次项目是基于SpringBoot+Vue的前后端分离项目,旨在熟练相关框架,掌握相关技术,拓展个人知识面。音乐来源:本地用户页面:Web项目亮点:根据歌词、音乐旋律、定位时间线(老师的意见)确定好方向,开始项目、收集资料、准备相关的开发环境和软件等。了解项目的结构与逻辑,确定基本功能,需求......
  • springboot~关于md5签名引发的问题
    事实是这样的,我有个接口,这个接口不能被篡改,于是想到了比较简单的md5对url地址参数进行加密,把这个密码当成是sign,然后服务端收到请求后,使用相同算法也生成sign,两个sign相同就正常没有被篡改过。问题的出现接口中的参数包括userId,extUserId,时间,其中extUserId字符编码,中间会有+......
  • springboot集成JWT token验证
    登录模式基于session登录基于session的登录(有回话状态),用户携带账号密码发送请求向服务器,服务器进行判断,成功后将用户信息放入session,用户发送请求判断session中是否有用户信息,有的话放行,没有的话进行拦截,但是考虑到时App产品,牵扯到要判断用户的session,需要sessionID,还要根据sess......
  • Springboot yml配置参数加密 ,jasypt自定义解密器
    原文链接:https://www.cnblogs.com/JCcccit/p/16868137.html前言 最近项目组开始关注一些敏感数据的明文相关的事宜,其实这些东西也是都有非常成熟的解决方案。既然最近着手去解决这些事情,那么也顺便给还未了解的大伙普及一下。Springbootyml配置参数数据加密(数据加密篇......
  • springboot使用mybatis应用clickhouse
    一、clickhouse,说白了还是数据库,不一样的是clickhouse是列式存储,和传统的MySQL行式存储不同的地方在于,查询和所储。1)查询,行式和列式的区别,图形说明说明:理解上来说,行式对于一条数据的完整性索引会更快。而列式对于统计和查询指定数据会更加块。2)数据......
  • 无法访问org.springframework.boot.SpringApplication
    用idea创建的springboot项目,版本不对。换成<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.5.6</version><!--2.7.10-->&l......
  • Springboot提高
    全局异常处理器未做处理的情况:当我没没有做任何异常处理时,mapper接口操作数据库出错时,会将异常向上抛给ServiceService中的异常会往上抛给controllercontroller会将异常抛给框架响应给浏览器一个JSON格式的数据这个数据并不符合我们统一响应结果的规范如何处理?方案一:......
  • Java__SpringBoot与Vue连接
    SpringBoot与Vue注解RequestMapping("/dir/")创建一个方便前端调用的接口目录/接口函数,前端可以获取到函数返回的数据@RestController@RequestMapping("/dir/")publicclassBotInfoController{@RequestMapping("getinfo/")publicMap<String,String>GetI......