A. Remove Duplicates

题意大概就是从左到右数字最先数完的最先输出

所以我们可以在输入每个数时记录每个数的出现次数,然后在循环一遍,每次该数字的次数减1,当数字的次数只剩1的时候就输出这个数字.

#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

题意大概就是说不能出现三个及以上的x

所以我们每找到一个x,就取找它后面有多少个x,如果大于2,ans就加上x的个数 - 2,因为题目要求是可以允许两个及以下x存在的

#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

题意大概就是给你n层楼,m封信件,再给你每层楼有多少房间和m件信封需要送到多少号房间

因为信封给的是房间号,所以我们可以先用前缀和将前面的房间存起来,对于每封信件我们可以二分找到房间数,然后减去它上层楼的房间数就是当前楼的第几间房了.

当然由于他给的信封房间号是保证递增的,也可以每次判断上一封信件放在几楼,再跟进当下的房间数在其基础上进行加多少房间或者不加(就在当前楼).

#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

题意大概就是对每个数+1,-1,或者不变,问是否可以组成一个等差数列

对于小于2个数的特殊处理一下,其余由于前面两个数三种变化各有9种组合方式,所以我们可以直接暴力求解

#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

题意大概就是给你公交车每站上下车的人数和公交车的最大限乘人数,问你在开始的时候公交车人数有多少情况

可以先求出前缀和,找到上车人数最多的时候,用限乘减去它就是可以在此之前车上最多承载的人数,当然也有可能全是下车的,所以也要找到下车人数最多的时候,即要保证在最开始车上有这么多人,当然车上最开始也是可以一个人都没有的,所以还要两者的差值再加上+1

 #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

题意大概就是给出n个人的能力值,能力值大的可以当能力值小的人的老师,但是现在有m个矛盾,发生矛盾的两人不能成为师生,问最后每个人可以当多少人的老师

可以先用a,b两个数组存能力值,对b数组排序,再用一个数组c存每个人可以成为多少人的老师,对循环a数组,对每个人的能力值去b数组中二分查找,其对应下标就是该数组a中能力值的人的学生数,最后对输入的各个矛盾,判断谁能力值更大,大的那个人学生数减1即可

#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();
}
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

题意大概就是学生要在n天内完成m场考试,给出每场考试知道的日期和考试日期以及需要为这场考试复习需要多少天,问能否给出一个合理的规划将所有每场考试开考前复习完,不能就输出-1,能就输出n天的规划

在输入的时候可以先标记每场考试的日期,在之后的考试日期有冲突的可以直接输出-1,再就是可以对每场考试按终止日期排序,在此之前每过一天就复习天数减1,如果到考试时复习天数还未减至0说明不能完成复习,直接输出-1即可

#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;
}

SMU Spring 2023 Trial Contest Round 10的更多相关文章

  1. Spring 源码学习笔记10——Spring AOP

    Spring 源码学习笔记10--Spring AOP 参考书籍<Spring技术内幕>Spring AOP的实现章节 书有点老,但是里面一些概念还是总结比较到位 源码基于Spring-a ...

  2. Codeforces Beta Round #10 D. LCIS

    题目链接: http://www.codeforces.com/contest/10/problem/D D. LCIS time limit per test:1 secondmemory limi ...

  3. spring security 3中的10个典型用法小结

    spring security 3比较庞大,但功能很强,下面小结下spring security 3中值得 注意的10个典型用法 1)多个authentication-provide可以同时使用 &l ...

  4. Codeforces Beta Round #10 D. LCIS 动态规划

    D. LCIS 题目连接: http://www.codeforces.com/contest/10/problem/D Description This problem differs from o ...

  5. Codeforces Beta Round #10 C. Digital Root 数学

    C. Digital Root 题目连接: http://www.codeforces.com/contest/10/problem/C Description Not long ago Billy ...

  6. Codeforces Beta Round #10 B. Cinema Cashier 暴力

    B. Cinema Cashier 题目连接: http://www.codeforces.com/contest/10/problem/B Description All cinema halls ...

  7. Codeforces Beta Round #10 A. Power Consumption Calculation 水题

    A. Power Consumption Calculation 题目连接: http://www.codeforces.com/contest/10/problem/A Description To ...

  8. Educational Codeforces Round 10 A. Gabriel and Caterpillar 模拟

    A. Gabriel and Caterpillar 题目连接: http://www.codeforces.com/contest/652/problem/A Description The 9-t ...

  9. spring 5.x 系列第10篇 —— 整合mongodb (代码配置方式)

    源码Gitub地址:https://github.com/heibaiying/spring-samples-for-all 一.说明 1.1 项目结构说明 配置文件位于com.heibaiying. ...

  10. # 曹工说Spring Boot源码(10)-- Spring解析xml文件,到底从中得到了什么(context:annotation-config 解析)

    写在前面的话 相关背景及资源: 曹工说Spring Boot源码(1)-- Bean Definition到底是什么,附spring思维导图分享 曹工说Spring Boot源码(2)-- Bean ...

随机推荐

  1. Linux 增加 swap 分区

    检查当前swap分区 [root@localhost ~]# free -g total used free shared buffers cached Mem: 15 0 14 0 0 0 -/+ ...

  2. python重拾第九天-进程、线程、协程

    本节内容 操作系统发展史介绍 进程.与线程区别 python GIL全局解释器锁 线程 语法 join 线程锁之Lock\Rlock\信号量 将线程变为守护进程 Event事件 queue队列 生产者 ...

  3. .NET 个人博客-给图片添加水印

    个人博客-给图片添加水印 前言 需要用到的库 SixLabors.lmageSharp 2.1.3 SixLabors.lmageSharp.Web 2.0.2 SixLabors.Fonts 1.0 ...

  4. 统信 UOS 重置Root账号密码 获取 Root 权限

    统信服务器默认无法用root 账号登入系统,用普通管理员登入后在切换至root账户下即可,初次使用系统时 切换至root账户前需要做很多配置 1.同信切换root账户首先要激活下系统,可以选择试用期激 ...

  5. 制作visual studio 离线安装包

    应用场景:脱机.内网环境安装vs开发环境. 概述:在互联网环境下载安装工具,下载根据需求并缓存布局(类似功能模块),压缩缓存内容拷贝至离线环境进行安装. 1.官网下载指定版本的vs安装客户端 创建基于 ...

  6. GraqphQL 学习

    GraphQL是Graph+QL.Graph是图,描述数据最好的方式是图数据结构(包括树),数据和数据之间,有像图一样的联系,以图的思维来考虑数据.QL是query language,像写query语 ...

  7. 粗枝大叶记录一下java9模块化改造一个项目的过程(Jigsaw)

    假设项目结构如下: 其中的依赖关系为 我实际用的jdk是17 1. common模块创建描述文件,在common的src/main/java下创建module-info.java, 内容默认 /** ...

  8. Spring里面bean的依赖和继承

    继承 bean继承:两个类之间大多数的属性都相同,避免重复配置,通过bean标签的parent属性重用已有的Bean元素的配置信息 继承指的是配置信息的复用,和java类的继承没有关系 video.j ...

  9. [oeasy]python0048_取整_int_float_浮点型_cast_扮演_tab_制表键_制表符

    转化为10进制 回忆上次内容 上次 把其他进制 转化回 十进制 用的是 int 函数 int 来自于 integer 同源词 还有 integrate entire 意思都是完整的 完整的 和 零散的 ...

  10. oeasy教您玩转vim - 20 - 显示标尺

    显示标尺 回忆上节课内容 定义标记 a ma 删除标记 a :delm a 跳转到标记 a 'a `a 跳到 a 对应的行和列 'a 跳到 a 对应的行 查看所有标记 :marks 各种标记类型 '' ...