SMU Summer 2023 Contest Round 7

A. Two Rival Students

  • 答案不能大于 \(n-1\);

  • 如果竞争对手之间的当前距离小于 \(n - 1\) ,我们总是可以将这个距离增加一个交换数;

即答案等于 \(min(n - 1,|a - b|+x)\)。

#include <bits/stdc++.h>
#define int long long using namespace std; signed main() { ios::sync_with_stdio(false);cin.tie(nullptr); int T;
cin >> T;
while(T--){
int n,x,a,b;
cin >> n >> x >> a >> b;
cout << min(abs(a - b) + x, n - 1) << endl;
} return 0;
}

B. Magic Stick

\(1\)不能转化为任何其他数 \(2\)可以转化为\(3\)或\(1\),而\(3\)只能转化为\(2\)。也就是说,如果是\(x = 1\),那么只有\(y = 1\)可以达到;如果是\(x = 2\)或\(x = 3\),那么\(y\)应该小于\(4\)。

否则,我们可以把 \(x\)设得越大越好,所以如果 \(x > 3\),那么任何 \(y\)都是可以达到的。

#include <bits/stdc++.h>
#define int long long using namespace std; signed main() { int T;
cin >> T;
while(T--){
int x,y;
cin >> x >> y; if (x > 3) puts("YES");
else if (x == 1) puts(y == 1 ? "YES" : "NO");
else puts(y <= 3 ? "YES" : "NO");
} return 0;
}

C. Dominated Subarray

  • 当\(n<2\)和所有数都只出现一次的时候,是不存在这种连续的子序列的
  • 要满足最短连续子序列,只要让一个数最多出现两次就好了,一个\(pos\)数组去记录每个数上次出现的下标,然后当它再次出现时,就用当前坐标减去上次出现的坐标就是一个序列的长度了,每次去更新最小值即可
#include <bits/stdc++.h>
#define int long long using namespace std; signed main() { ios::sync_with_stdio(false);cin.tie(nullptr); int T;
cin >> T;
while(T--){
int n;
cin >> n;
int ma = 0;
vector<int> a(n),t(n + 1),pos(n + 1, -1);
for(auto& i : a) {
cin >> i;
t[i] ++;
ma = max(ma, t[i]);
} if(n < 2 || ma == 1){
cout << -1 << endl;
continue ;
} int mi = 0x3f3f3f3f3f3f;
for(int i = 0;i < n;i++){
if(pos[a[i]] != -1)
mi = min(mi, i - pos[a[i]] + 1);
pos[a[i]] = i;
} cout << mi << endl;
} return 0;
}

D. Yet Another Monster Killing Problem(二分+贪心)

  • 当英雄里最大的力量值也小于怪兽里最大的力量值得话,英雄们就不能全部打败怪兽了

  • 若力量值为\(p_i\)的英雄能杀死怪兽,则比他大的也一定能打败怪兽,所以我们可以先对力量值排序

    若力量值大的耐久值也高,则他完全可以代替力量值耐久值都比不过他的英雄,所以我们可以从大到小将耐久值更新为后面英雄的最大耐久值,即\(S_i < S_j\),则把\(S_i\)更新为\(max_{i \leq j \leq m}S_j\).

    然后我们可以去枚举每个怪兽,去维护一个当天能打败的最大怪兽数,即打败怪兽的英雄的最小耐久值\(nows\),直到当天能打败的怪兽数和之前打败的怪兽数之和小于了当前所在怪兽数,就是说怪兽已经超过了当天能打败的最大数,那我们就可以把他们消灭掉,然后进入下一天了.

#include <bits/stdc++.h>
#define int long long using namespace std; typedef pair<int,int> PII; signed main() { ios::sync_with_stdio(false);cin.tie(nullptr); int T;
cin >> T;
while(T--){
int n,m,MaxMonster = 0, MaxHero = 0;
cin >> n;
vector<int> a(n);
for(auto &i : a) {
cin >> i;
MaxMonster = max(MaxMonster , i);
}
cin >> m;
vector<PII> ps(m);
for(auto &[p,s] : ps){
cin >> p >> s;
MaxHero = max(MaxHero, p);
} if(MaxMonster > MaxHero){
cout << -1 << endl;
continue ;
} sort(ps.begin(),ps.end());
for(int i = m - 2;i >= 0;i--)
ps[i].second = max(ps[i + 1].second, ps[i].second); int ans = 1, nowkill = 0,nows = 0x3f3f3f3f3f3f;
for(int i = 0;i < n;i ++){
int now = lower_bound(ps.begin(),ps.end(),PII(a[i],0)) - ps.begin(); nows = min(nows, ps[now].second);
if(nows + nowkill <= i){
nows = ps[now].second;
ans++;
nowkill = i;
} }
cout << ans << endl;
} return 0;
}

SMU Summer 2023 Contest Round 7的更多相关文章

  1. 2015 Astar Contest - Round 3 题解

    1001 数长方形 题目大意 平面内有N条平行于坐标轴的线段,且不会在端点处相交 问共形成多少个矩形 算法思路 枚举4条线段的全部组合.分别作为矩形四条边.推断是否合法 时间复杂度: O(N4) 代码 ...

  2. Contest Round #451 (Div. 2)F/Problemset 898F Restoring the Expression

    题意: 有一个a+b=c的等式,去掉两个符号,把三个数连在一起得到一个数 给出这个数,要求还原等式,length <= 1e6 三个数不能含有前导0,保证有解 解法: 铁头过题法,分类然后各种判 ...

  3. Codeforces Round #284 (Div. 2)A B C 模拟 数学

    A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. Sending messages to non-windowed applications -- AllocateHWnd, DeallocateHWnd

    http://delphi.about.com/od/windowsshellapi/l/aa093003a.htm Page 1: How Delphi dispatches messages in ...

  5. Codeforces 240 F. TorCoder

    F. TorCoder time limit per test 3 seconds memory limit per test 256 megabytes input input.txt output ...

  6. cf499B-Lecture 【map】

    http://codeforces.com/problemset/problem/499/B B. Lecture     You have a new professor of graph theo ...

  7. Codeforces 240F. TorCoder 线段树

    线段树统计和维护某一区间内的字母个数.. . . F. TorCoder time limit per test 3 seconds memory limit per test 256 megabyt ...

  8. 物联网学生科协第三届H-star现场编程比赛

    问题 A: 剪纸片 时间限制: 1 Sec 内存限制: 128 MB 题目描写叙述 这是一道简单的题目,假如你身边有一张纸.一把剪刀.在H-star的比赛现场,你会这么做: 1. 将这张纸剪成两片(平 ...

  9. [cf contest 893(edu round 33)] F - Subtree Minimum Query

    [cf contest 893(edu round 33)] F - Subtree Minimum Query time limit per test 6 seconds memory limit ...

  10. 水题 Codeforces Round #307 (Div. 2) A. GukiZ and Contest

    题目传送门 /* 水题:开个结构体,rk记录排名,相同的值有相同的排名 */ #include <cstdio> #include <cstring> #include < ...

随机推荐

  1. 一行超长日志引发的 “血案” - Containerd 频繁 OOM 背后的真相

    案发现场:混沌初现 2024年6月10日,本应是平静的一天.但从上午 9 点开始,Sealos 公有云的运维监控告警就开始不停地响.北京可用区服务器节点突然出现大量 "not ready&q ...

  2. tortoisegit 配置ssh登录

    习惯使用小乌龟. 服务器:gitblit 客户端:TortoiseGit 2.13.0.1 (C:\Program Files\TortoiseGit\bin) git version 2.36.1. ...

  3. ansible(1)---师傅领进门

    背景 在企业里,运维需要配合开发进行产品上架,说白了就是把写好的代码上服务器.那么,就会出现这样的问题:需要运维人员配置好系统,配置好环境,配置好网络,配置好程序,配置好所有所有的依赖环境.     ...

  4. AtCoder Beginner Contest 302 H. Ball Collector 题解 可撤销并查集

    为了更好的阅读体验,请单击这里 AtCoder Beginner Contest 302 H. Ball Collector 题意跳过. 可以视作将 \(a_i, b_i\) 之间连了一条边,然后 \ ...

  5. invalid comparison: java.util.Date and java.lang.String异常的原因

    mybatis查询时使用date类型与""比较导致的 例 <if test="params.applicationEndTime != null and param ...

  6. Tutorial: How to install GNU MCU Eclipse?

    Overview For more flexibility and upgradeability, GNU MCU Eclipse is not packed as a all-inclusive s ...

  7. 【论文阅读】IROS2017: Voxblox & RAL2019: Voxblox++

    IROS2017: Voxblox & RAL2019: Voxblox++ Status: Finished Type: RAL Year: 2019 组织/Sensor: ETH-ASL ...

  8. Spring Reactor基本介绍和案例

    1. Reactor 对比 1.1 Reactor 线程模型 Reactor 线程模型就是通过 单个线程 使用 Java NIO 包中的 Selector 的 select()方法,进行监听.当获取到 ...

  9. VS2017 error CS0234: 命名空间“Microsoft”中不存在类型或命名空间名“Office”问题的一种解决方案

    最近需要使用VS2017编辑C#,但在编译时软件报错:error CS0234: 命名空间"Microsoft"中不存在类型或命名空间名"Office" 在网上 ...

  10. 使用requests库实现http请求

    1.发送请求 import requests url = 'http://www.tipdm.com/tipdm/index.html' rqq = requests.get(url) In [ ]: ...