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

SMU Spring 2023 Trial Contest Round 10

时间:2023-05-04 22:13:51浏览次数:47  
标签:10 typedef scholar Contest int Spring cin long define

A. Remove Duplicates

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

using namespace std;

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

//typedef long long ll;
typedef pair<int,int> PII;
//queue<PII> q1;
map<vector<int>, int > mp;
//priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t,k;
/*
*/
vector<int> a, b;
void solve()
{
    cin >> n;
    set<int> S;
    vector<int> a,b;
    int vis[N] = {0};
    for(int i = 0;i < n; i++){
        int x;
        cin >> x;
        vis[x] ++;
        a.push_back(x);
    }
    for(int i = 0;i < a.size(); i++){
        if(vis[a[i]] == 1){
            b.push_back(a[i]);
        }
        else
        vis[a[i]]--;
    }
    cout << b.size() << endl;
    for(auto i : b){
        cout << i << ' ' ;
    }
}
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;
}

 

B. File Name

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

using namespace std;

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

//typedef long long ll;
typedef pair<int,int> PII;
//queue<PII> q1;
map<vector<int>, int > mp;
//priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t,k;
/*
*/
vector<int> a, b;
void solve()
{
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i]!='x')
            continue;
        m = i;
        while(s[i] == 'x' && i < s.size()){
            i++;
        }
        if(i - m > 2)
            ans += (i - m - 2);
    }
    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;
}

 

C. Letters

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

using namespace std;

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

//typedef long long ll;
typedef pair<int,int> PII;
//queue<PII> q1;
map<vector<int>, int > mp;
//priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t,k;
/*
*/
vector<int> a, b;
void solve()
{
    cin >> n >> m;
    vector<int> a,b;
    cin >> k;
    a.push_back(k);
    for(int i = 1;i < n; i++){
        int x;
        cin >> x;
        a.push_back(x + a[i - 1]);
    }
    for(int i = 0 ;i < m; i++){
        int x;
        cin >> x;
            auto it = lower_bound(a.begin(),a.end(),x) - a.begin();
           if(lower_bound(a.begin(),a.end(),x) == a.begin())
               cout << 1 << ' ' << x << endl;
           else
               cout << it + 1 << ' ' << x - a[it - 1] << 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;
}

 

D.Almost Arithmetic Progression

#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;
map<vector<int>, int > mp;
//priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t;
/*
*/
void solve()
{
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n; i++){
        cin >> a[i];
    }
    if(n <= 2){
        cout << 0 << endl;
        return ;
    }
    int ans = inf;
    for(int i = -1;i <= 1;i ++){
        for(int j = -1; j<= 1; j++){
            vector<int> b(a);
            b[0] += i;
            b[1] += j;
            int d = b[1] - b[0];
            int res = abs(i) + abs(j);
            for(int k = 2; k < n && res <= ans; k++){
                int dd = b[k] - b[k - 1];
                if (dd == d)
                    continue;
                else if(dd == d + 1){
                    b[k]--;
                    res ++;
                }
                else if(dd == d - 1){
                    b[k] ++;
                    res ++;
                }
                else
                    res = inf;
            }
            ans = min(res, ans);
        }
    }
    if(ans == inf)
        cout << -1 << endl;
    else
        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;
}

 

E.Bus Video System

 #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;
map<vector<int>, int > mp;
//priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t;
/*
*/
int a[N];
void solve()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        a[i] = a[i] + a[i - 1];
    }
    int r = min(m, m - *max_element(a + 1, a + n + 1));
    int l = max(0ll, -*min_element(a + 1, a + n + 1));
    cout << max(0ll, r - l + 1) << 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;
}

 

F.Mentors

#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;
map<vector<int>, int > mp;
//priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t,k;
/*
*/
int a[N];
void solve()
{
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0;i < n; i++){
        cin >> a[i];
    }
    auto b = a;
    vector<int> c(n,0);
    sort(b.begin(), b.end());
    for(int i = 0;i < a.size(); i++){
        c[i] = lower_bound(b.begin(), b.end(),a[i]) - b.begin();
    }
//    for(auto i : c)
//        cout << i << ' ';
//    cout << endl;
    while(k--){
        int x,y;
        cin >> x >> y;
        x--,y--;
        if(a[x] > a[y])
            c[x]--;
        else if(a[x] < a[y])
            c[y]--;
    }
    for(auto i : c)
        cout << i << ' ';
}
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;
}

 

G.Petya's Exams

#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;
map<vector<int>, int > mp;
//priority_queue <int,vector<int>,greater<int> > q2;
int n,m,t,k;
/*
*/
int a[N];
struct Time{
    int s,e,d,id;
    bool operator < (const Time &s)const {
        if(e != s.e) return e < s.e;
    }
}day[N];
void solve()
{
    cin >> n >> m;
    vector<int> a(n + 1);
    for(int i = 0;i < m; i++){
        cin >> day[i].s >> day[i].e >> day[i].d ;
        day[i].id = i + 1;
        if(a[day[i].e]) {
            puts("-1");
            exit(0);
        }
        a[day[i].e] = m + 1;
    }
    sort(day, day + n);
    for(auto [s,e,d,id] : day){
        for(int i = s;i < e && d > 0; i++){
            if(a[i])
                continue;
            a[i] = id;
            d--;
        }
        if(d == 0)
            continue;
        puts("-1");
        exit(0);
    }
    for(int i = 1;i <= n; i++){
        cout << a[i] << ' ';
    }
}
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;
}

 

标签:10,typedef,scholar,Contest,int,Spring,cin,long,define
From: https://www.cnblogs.com/Kescholar/p/17372679.html

相关文章

  • 日本「AI 鱼脸识别」项目,每分钟识别 100 条
    By超神经内容提要:近日,日本的一个AI分拣鱼类项目进入实验阶段。这将有望改善日本渔业劳动力老龄化及短缺的社会现状。关键词:AI分拣鱼类计算机视觉日本作为岛国,其独特的地理位置,让国民自古以来就跟鱼结下了不解之缘,甚至形成了其独特的「鱼文化」。因此,日本无论是在养鱼、捕鱼还......
  • win10家庭版没有Hyper-v的解决方法
    pushd"%~dp0"dir/b%SystemRoot%\servicing\Packages\*Hyper-V*.mum>hyper-v.txtfor/f%%iin('findstr/i.hyper-v.txt2^>nul')dodism/online/norestart/add-package:"%SystemRoot%\servicing\Packages\%%i"delh......
  • 2106. 摘水果
    题目链接:2106.摘水果方法:滑动窗口解题思路从\(startPos\)所能到达的最左端\((>=startPos-k)\)的位置\(left\)开始,初始化右指针\(right=left\),\(right\)右移至\(startPos\),因为不知道继续右移能不能到达;当右移超过\(startPos\)时,可能有两种情况:\(startPos......
  • Spring源码:Bean生命周期(三)
    前言在之前的文章中,我们已经对bean的准备工作进行了讲解,包括bean定义和FactoryBean判断等。在这个基础上,我们可以更加深入地理解getBean方法的实现逻辑,并在后续的学习中更好地掌握createBean方法的实现细节。getBean用法讲解getBean方法之前,我们先来看看他有几种常见......
  • 探究Spring中Bean的线程安全性问题
    前言  今天同事笑嘻嘻的凑过来,问了我一个问题:spring中的bean是线程安全的吗?。我内心一想肯定是安全的,毕竟这样多项目在用。但是转念一想,他那贱兮兮的表情,多半是在给我挖坑。于是我自信的回答他:不安全。他反问,你确定......
  • SpringCloud gatewayeFilter之一
    1、AddRequestHeaderGatewayFilterAddRequestHeaderGatewayFilter采用名称和值参数。例如:spring:cloud:gateway:enabled:trueroutes:-id:Goods-Server#路由id,唯一标识uri:lb://producerpredicates:......
  • 从功能测试转型测试开发,薪资涨了20K,1000字讲述转型必经之路...
    身处职场之中,犹如逆水行舟不进则退,想要不被后浪拍死在沙滩上,就要不断学习新知识,接受新事物。要得到更好的发展,就要紧跟发展趋势,不断转型才能保持竞争力,在职场中占有一席之地。转型不是一件容易的事,涉及到转型、革新,就要突破现有的框架,必然会经历阵痛。我刚工作时就是一名月薪40......
  • GYM 101147K Touristic Trip
    首先可以看出这是一个条件概率\(P(A/B)=\frac{P(AB)}{P(B)}\),其中\(A\)事件为“满足在\(Z\)城市时寄出第\(Q\)张明信片”,\(B\)事件为“满足得到的明信片序列与给出的明信片序列相同”那只需要求出\(P(AB)\)和\(P(B)\)就能得到最终答案了首先考虑\(B\)事件发现......
  • springboot 项目国际化+登录拦截器
    项目页面国际化1.语言配置文件需要下载插件ResourceBundleEditor 新建国际目录i18n 在properties配置文件中自定义  2.前端index页面要设置语言参数传递给后端,切换中英文 3.自定义地区解析器MyLocaleResolver后端接收并处理 4.自定义了一个地区解析器要生效......
  • springboot mvc配置原理+扩展springmvc(重点)
    1.新建config目录2.在config目录下创建自定义配置类3.根据官方文档得到要有注解@Configuration并且继承类WebMvcConfigurer 扩展springmvc:我们慢慢脱离了原始的繁琐的xml配置,现在转向javaconfig配置 最后扩展->springmvc配置原理源码:注意点:springmvc的配置在springboo......