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. Jenkins构建UI自动化项目,指定本地执行,没弹起浏览显示

    1. 原因分析 为什么执行web没有弹出浏览器,Jenkins日志显示正在执行中 jenkins是用windows installer 安装成 windows的服务了,那么启动windows后jenk ...

  2. 11-DNS域名解析服务

    背景 我们都知道,用ip可以唯一标识互联网上的主机. 从前,互联网的主机非常的少.我们都可以记住每台Server的ip. 就像是大哥大时期,电话非常少,电话号码也就非常少,我们都能记住某个人的电话. ...

  3. 第三方App与Termux命令建立IO通道

    目录 前言 一.Android 进程间通信(IPC) 二.Netcat 网络瑞士军刀 三.第三方 App 与 Termux 建立 TCP/Socket 通信 四.应用:调用 LSP 语言服务器 参见 ...

  4. 在Linux驱动中使用input子系统

    在Linux驱动中使用输入子系统 参考: https://www.cnblogs.com/lifexy/p/7553861.html https://www.cnblogs.com/linux-37g ...

  5. paraview安装

    apt 安装 sudo apt install paraview 安装包安装 参考 https://blog.csdn.net/weixin_47492286/article/details/1272 ...

  6. python基础-字典dict {key:value }

    字典的定义和操作 字典的特性: 元素数量 支持多个 元素类型 key :value key:除字典外的任何类型 Value:任何类型 下标索引 不支持 重复元素 key不支持 可修改性 支持 数据有序 ...

  7. 都是全志T113处理器,“-i”和“-S3”有什么区别?

    自9个月前,创龙科技"1片含税就79元"的全志T113-i双核ARM Cortex-A7@1.2GHz的工业核心板(SOM-TLT113)推出之后,不少嵌入式软硬件工程师.用户都咨 ...

  8. 牛客小白月赛97 A-D题解

    AAAAAAAAAAAAAAAAAAAAA -----------------------------题解------------------------------------------- 统计数 ...

  9. 制作visual studio 离线安装包

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

  10. java开发webservice报Service(URL, QName, WebServiceFeature[]) is undefined错误的解决方法

    Description Resource Path Location TypeThe constructor Service(URL, QName, WebServiceFeature[]) is u ...