SMU Summer 2023 Contest Round 1
SMU Summer 2023 Contest Round 1
A. The Contest
当 \(m\) 为 \(0\) 和 完成时间大于最后一个时刻时,说明都无法在规定条件内完成,输出\(-1\).
将时间段拆开放一个数组循环, 找到第一个大于等于完成时间的位置,若此时\(i\) 为奇数, 说明该完成时间处在一个工作时间段内,输出\(sum\)即可, 否则就是处于非工作时间,这时就要输出下一个工作时间段的开始时刻.
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
int n,m,t,k;
void solve(){
cin >> n;
vector<int> a(n);
int sum = 0;
for(auto &i : a){
cin >> i;
sum += i;
}
cin >> m;
if(!m){
cout << -1 << endl;
return ;
}
vector<int> time;
for(int i = 0;i < m;i ++){
cin >> t >> k;
time.push_back(t);
time.push_back(k);
}
if(sum > time.back()){
cout << -1 << endl;
return ;
}else {
for(int i = 0;i < time.size();i ++){
if(time[i] >= sum){
if(i & 1){
cout << sum << endl;
break;
}else{
cout << time[i] << endl;
break;
}
}
}
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int Ke_scholar = 1;
// cin >> Ke_scholar;
while(Ke_scholar--)
solve();
return 0;
}
B. The Golden Age
暴力将区间内的不吉利数算出后排序,更新区间最大值即可.(注意精度问题)
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define inf 0x3f3f3f3f
using namespace std;
int n,m,t,k;
void solve(){
int x,y,l,r;
cin >> x >> y >> l >> r;
vector<int> ans;
for(int i = 1; i != 0; i = i * (i > r / x ? 0 : x))//当值超过r时就不取,防止爆精度
for(int j = 1;j != 0; j = j * (j > r / y ? 0 : y))
if(i + j >= l && i + j <= r)
ans.push_back(i + j);
int res = 0;
if(ans.size()) {
int L = l - 1;
sort(ans.begin(), ans.end());
for(int i = 0; i < ans.size();i ++){
res = max(res, ans[i] - L - 1);
L = ans[i];
}
if (ans.front() != l)
res = max(ans.front() - l, res);
if (ans.back() != r) {
res = max(r - ans.back(), res);
}
}else{
res = r - l + 1;
}
cout << res << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int Ke_scholar = 1;
// cin >> Ke_scholar;
while(Ke_scholar--)
solve();
return 0;
}
C. The Tag Games
要使得行动步数最长,则\(B\)就要找到一条\(A\)与\(B\)路径上的最长链, 因此我们可以先建一个图, 对每个点找到它当前点向后延伸的最长链长度,然后用path数组去记录\(A\)与\(B\)的这条路径,在这条路径上找到\(A\)能到达最长链的最大值
\(i\) 就是A行动的步长.
\(deep[path[i]] - deep[path[j]]\) 就是\(A\) 与 \(B\) 之间的距离.
\(dis[path[i]] - 1\)就是\(B\)当前所在点距离最长链的长度.
因为更新的这个值是\(A\)到达最长链的长度,且\(A\)与\(B\)的步数是同步的,所以最后需要\(×2\)
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define inf 0x3f3f3f3f
using namespace std;
const int N = 2e5 + 10, mod = 1e18;
typedef pair<int,int> PII;
int n,m,t,k;
void solve(){
cin >> n >> m;
vector<int> g[n + 1];
for(int i = 0;i < n - 1;i ++){
int x,y;
cin >>x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
vector<int> pre(n + 1),deep(n + 1),dis(n + 1),path(n + 1);
function<int(int,int,int)> dfs = [&](int u,int v, int d){
int len = 0;
pre[u] = v;
deep[u] = d;
for(auto i : g[u]){
if(i == pre[u])
continue;
len = max(len, dfs(i,u,d + 1));
}
return dis[u] = len + 1;
};
dfs(1, -1, 0);
t = m;
int cnt = 0;
while(t != - 1){
path[cnt++] = t;
t = pre[t];
}
int ans = 0;
for(int i = 0, j = cnt - 1;i < j; j --, i ++){
ans = max(ans, (i + deep[path[i]] - deep[path[j]] + dis[path[i]] - 1) * 2);
}
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int Ke_scholar = 1;
// cin >> Ke_scholar;
while(Ke_scholar--)
solve();
return 0;
}
SMU Summer 2023 Contest Round 1的更多相关文章
- 2015 Astar Contest - Round 3 题解
1001 数长方形 题目大意 平面内有N条平行于坐标轴的线段,且不会在端点处相交 问共形成多少个矩形 算法思路 枚举4条线段的全部组合.分别作为矩形四条边.推断是否合法 时间复杂度: O(N4) 代码 ...
- Contest Round #451 (Div. 2)F/Problemset 898F Restoring the Expression
题意: 有一个a+b=c的等式,去掉两个符号,把三个数连在一起得到一个数 给出这个数,要求还原等式,length <= 1e6 三个数不能含有前导0,保证有解 解法: 铁头过题法,分类然后各种判 ...
- 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 ...
- Sending messages to non-windowed applications -- AllocateHWnd, DeallocateHWnd
http://delphi.about.com/od/windowsshellapi/l/aa093003a.htm Page 1: How Delphi dispatches messages in ...
- Codeforces 240 F. TorCoder
F. TorCoder time limit per test 3 seconds memory limit per test 256 megabytes input input.txt output ...
- cf499B-Lecture 【map】
http://codeforces.com/problemset/problem/499/B B. Lecture You have a new professor of graph theo ...
- Codeforces 240F. TorCoder 线段树
线段树统计和维护某一区间内的字母个数.. . . F. TorCoder time limit per test 3 seconds memory limit per test 256 megabyt ...
- 物联网学生科协第三届H-star现场编程比赛
问题 A: 剪纸片 时间限制: 1 Sec 内存限制: 128 MB 题目描写叙述 这是一道简单的题目,假如你身边有一张纸.一把剪刀.在H-star的比赛现场,你会这么做: 1. 将这张纸剪成两片(平 ...
- [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 ...
- 水题 Codeforces Round #307 (Div. 2) A. GukiZ and Contest
题目传送门 /* 水题:开个结构体,rk记录排名,相同的值有相同的排名 */ #include <cstdio> #include <cstring> #include < ...
随机推荐
- 如何拥抱AI
从去年年初开始,AI技术真正走入了我们的日常生活.从OpenAI到如今字节跳动的coze,我们通过AI大模型可以做很多事情,工具和平台众多,如何选择和使用有必要总结一下. 编程和debug方面 尽管g ...
- Android 耳机驱动知识
Android 耳机驱动知识 2015-03-06 工作以后接手的第一个驱动就是android平台下耳机的插拔检测和按键检测.这部分涉及的硬件知识比较简单,但是软件上对中断的处理,软件检测的鲁棒性,都 ...
- 基于 SQLite 3 的 C 学习:1-开发流程 与 基本函数
背景 SQLite 是 一个 常用于 嵌入式平台的 轻量级的 关系型数据库. 我们已经介绍了 移植 SQLite 3 ,这一讲我们来介绍它的开发,这里仅仅涉及最基本的开发. 高级api:https:/ ...
- 题解:洛谷 P1165 日志分析
标签:栈,模拟 题意 对于一个栈,给定三种操作: 0 x,将 \(x\) 入栈: 1,出栈,栈空时忽略: 2,查询当前栈内最大值. 思路 前两个都是栈的基本操作,关键在于查最大值. 每次询问暴力找肯定 ...
- 最新最全的BMS/EMS/PCS六大国产“储能方案”,不信你全都看过!
作为国内领先的嵌入式产品平台提供商,创龙科技在"能源电力"行业拥有超过1000家客户,接下来就让小编向大家分享创龙科技推出的BMS/EMS/PCS"六大储能方案" ...
- java将list中某个元素放在首位
java将list中某个元素放在首位 1 List<Example> example = exampleRepository.list(); 2 3 //将list里的某个字符串默认排列在 ...
- 基于EF Core存储的国际化服务
前言 .NET 官方有一个用来管理国际化资源的扩展包Microsoft.Extensions.Localization,ASP.NET Core也用这个来实现国际化功能.但是这个包的翻译数据是使用re ...
- MobaXterm是一款功能强大的远程SSH利器,是您远程计算机的终极工具箱
MobaXterm 是一款功能强大的远程终端应用,可以用于 Windows 系统上的 SSH.Telnet.RDP.VNC 等远程登录.它支持多种会话类型,拥有强大的终端功能,还支持 X11 图形界面 ...
- SDL3 入门(5):纹理渲染
创建纹理 有三个 API 可以用来创建纹理: SDL_CreateTexture 参数少,使用方便,适用于创建简单的纹理 SDL_CreateTextureFromSurface 适用于从已有图像数据 ...
- AT_arc113_c 题解
洛谷链接&Atcoder 链接 本篇题解为此题较简单做法及较少码量,并且码风优良,请放心阅读. 题目简述 现在有一个字符串 \(S\),每一次你可以选择一个 \(i(1 \le i \le | ...