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的更多相关文章

  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. Mirror多人联网发布阿里云

    Mirror多人联网发布阿里云 新建模板小书匠 将mirror网络地址和端口选为你阿里云服务器上开放的公网地址和端口 IP与端口 2. 在阿里云服务器安全组中开放你所制定的端口 开放阿里云端口 3. ...

  2. [flask]统一API响应格式

    前言 在设计API返回内容时,通常需要与前端约定好API返回响应体内容的格式.这样方便前端进行数据反序列化时相应的解析处理,也方便其它服务调用.不同公司有不同的响应内容规范要求,这里以常见的JSON响 ...

  3. 【VMware vSphere】使用RVTools中的PowerShell脚本创建导出vSphere环境信息的自动化任务。

    RVTools 是 VMware 生态系统中一个非常受欢迎且免费的 Windows 实用工具,用于收集并显示 VMware vSphere 环境中的相关信息,如虚拟机.主机及集群等相关配置.RVToo ...

  4. 基于 Termux 和 ipv6 把手机打造成公网服务器

    Termux 安装与配置 安装 从这下载: https://f-droid.org/en/packages/com.termux/ 初始化 授权读写手机储存 termux-setup-storage ...

  5. python中dict和list的数据结构

    要理解dict的有关内容需要你理解哈希表(map)的相关基础知识,这个其实是<算法与数据结构>里面的内容. 1.list和tuple其实是用链表顺序存储的,也就是前一个元素中存储了下一个元 ...

  6. 算法金 | Transformer,一个神奇的算法模型!!

    大侠幸会,在下全网同名「算法金」 0 基础转 AI 上岸,多个算法赛 Top 「日更万日,让更多人享受智能乐趣」 抱个拳,送个礼 在现代自然语言处理(NLP)领域,Transformer 模型的出现带 ...

  7. Cannot add or update a child row: a foreign key constraint fails

    在使用Django添加用户时出现报错: 1 django.db.utils.IntegrityError: (1452, 'Cannot add or update a child row: a fo ...

  8. 图表绘制之RepeatNode的妙用

    图表绘制之RepeatNode的妙用 前言 最近接到许多大屏项目,其中有一个智慧大楼的项目,大致是由3d场景+数据图表组成,需要能监控实时数据.安防 监控.出入统计以及消防安全等功能如下图 但是在开发 ...

  9. 怒肝半月!Python 学习路线+资源大汇总

    Python 学习路线 by 鱼皮. 原创不易,请勿抄袭,违者必究! 大家好,我是鱼皮,肝了十天左右的 Python 学习路线终于来了~ 和之前一样,在看路线前,建议大家先通过以下视频了解几个问题: ...

  10. 为什么学编程都从helloworld开始?

    你好世界 回忆上次内容 上次 了解了 游乐场规则 REPL       添加图片注释,不超过 140 字(可选)   print函数 可以输出 字符串"h"     添加图片注释, ...