SMU Autumn 2023 Round 5

A. Everyone Loves to Sleep

把时间都转成分钟,然后存起来,二分找到离他睡觉点最近的一个时间段,减去他的睡觉点,如果最近的在第二天,则把中间的这段时间加起来

#include <bits/stdc++.h>
#define int long long
#define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std; void solve() { int n, H, M;
cin >> n >> H >> M;
int HM = H * 60 + M; set<int> s;
s.insert(INT_MAX);
for (int i = 0; i < n; i ++) {
int n, m;
cin >> n >> m;
s.insert(n * 60 + m);
} auto t = s.lower_bound(HM);
int ans ;
if (*t == INT_MAX) {
t = s.begin();
ans = 24 * 60 - HM + *t;
} else
ans = *t - HM;
cout << ans / 60 << ' ' << ans % 60 << '\n';
} signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int T;
cin >> T;
while (T--) {
solve();
} return 0;
}

B. Minimum Varied Number

倒着搜一遍即可,正着搜会超时,也可以直接打表

#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std;
using i64 = long long; typedef pair<i64, i64> PII; int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int T;
cin >> T;
while (T--) {
int n;
cin >> n;
bitset<10> v;
vector<int> ans;
bool ok = false;
auto dfs = [&](auto self, int sum) {
if(ok) return;
if (sum == n) {
ok = true;
reverse(ans.begin(), ans.end());
for (auto i : ans)
cout << i ;
cout << '\n';
return ;
}
for (int i = 9; i >= 1; i --)
if (!v[i]) {
v[i] = 1;
ans.push_back(i);
self(self, sum + i);
v[i] = 0;
ans.pop_back();
}
}; dfs(dfs, 0); } return 0;
}

D. Add Modulo 10

对于以\(1,3,7,9\)结尾的经过几次运算最后都会变成\(2,4,8,6\)的循环,而对于\(5,0\)结尾的,最后都会变成\(0\)结尾,所以我们可以先把不是以\(2\)结尾的都经过几次运算直到以\(2\)结尾,然后去模上\(20(2+4+8+6)\),就能把这些数都转换到\(20\)以内,然后就是比较一下就好了

#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std;
using i64 = long long; typedef pair<i64, i64> PII; int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int T;
cin >> T;
while(T--){
int n;
cin >> n;
vector<i64> a(n);
for(auto &i : a) cin >> i; bool f = true;
for(auto &i : a){
while(i % 10 != 2 && i % 10 != 0)
i += i % 10;
if(i % 10 == 2)
i %= 20;
} for(int i = 0;i + 1 < n;i ++)
if(a[i] != a[i + 1])
f = false; cout << (f ? "Yes" : "No") << '\n';
} return 0;
}

G. Make Them Equal(dp)

假设将\(a_i\)变成\(b_i\)需要\(f_i\)个操作数,你现在能操作\(k\)步,每个\(f_i\)操作可以使你获得\(c_i\)个硬币,问现在怎样使你得到的硬币数最大?

是不是很熟悉?

假如我将问题转换成:你现在有\(V\)体积的背包,你可以装\(n\)个物品,每个物品体积为\(v_i\),价值为\(c_i\),问你现在能装的最大价值是多少?

没错,就是很典型的背包题,只要我们预处理出\(f_i\),那么这个题也就迎刃而解了!

如果你没有判断$k \geq \sum\limits_{i=1}^{n}f_i $这一步的话,那么你就不能开#define int long long.

#include <bits/stdc++.h>
#define int long long
#define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std; vector<int> f(2048, INT_MAX); void solve() {
int n, k;
cin >> n >> k;
vector<int> b(n), c(n);
int sum = 0, ans = 0;
for (auto &i : b) {
cin >> i;
sum += f[i];
}
for (auto &i : c) {
cin >> i;
ans += i;
} if(k >= sum){
cout << ans << '\n';
return ;
} vector<int> dp(k + 1);
for (int i = 0; i < n; i ++)
for (int j = k; j >= f[b[i]]; j--)
dp[j] = max(dp[j - f[b[i]]] + c[i], dp[j]); cout << dp[k] << '\n';
} signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); f[1] = 0;
for (int i = 1; i <= 1000; i ++)
for (int j = 1; j <= i; j ++)
f[i + i / j] = min(f[i + i / j], f[i] + 1); int T;
cin >> T;
while (T--) {
solve();
} return 0;
}

I. Div. 7

如果能整除直接就输出,否则就去枚举它的个位

#include <bits/stdc++.h>
#define int long long
#define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std; void solve() {
int n;
cin >> n;
if(n % 7 == 0){
cout << n << '\n';
}else{
for(int i = 0;i <= 9;i ++){
if((n / 10 * 10 + i) % 7 == 0){
cout << (n / 10 * 10 + i) << '\n';
return ;
}
}
}
} signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int T;
cin >> T;
while (T--) {
solve();
} return 0;
}

SMU Autumn 2023 Round 5的更多相关文章

  1. Codeforces Round #845 (Div. 2) and ByteRace 2023 A-D

    Codeforces Round #845 (Div. 2) and ByteRace 2023 A-D A. Everybody Likes Good Arrays! 题意:对给定数组进行操作:删除 ...

  2. CodeForce——Deltix Round, Autumn 2021 (open for everyone, rated, Div. 1 + Div. 2)前三道题目题解

    目录 A: B: C: 题目链接 A Divide and Multiply standard input/output 1 s, 256 MB 正在上传-重新上传取消 x13036 B Willia ...

  3. 2023 01 19 HW

    2023 01 19 HW Okay, then let's start.  Okay. Maybe Karina, we start with the C2 design freeze. Yeah, ...

  4. SQL Server 随机数,随机区间,随机抽取数据rand(),floor(),ceiling(),round(),newid()函数等

    在查询分析器中执行:select rand(),可以看到结果会是类似于这样的随机小数:0.36361513486289558,像这样的小数在实际应用中用得不多,一般要取随机数都会取随机整数.那就看下面 ...

  5. SQL中Round(),Floor(),Ceiling()函数的浅析

    项目中的一个功能模块上用到了标量值函数,函数中又有ceiling()函数的用法,自己找了一些资料,对SQL中这几个函数做一个简单的记录,方便自己学习.有不足之处欢迎拍砖补充 1.round()函数遵循 ...

  6. oracle的round函数和trunc函数

    --Oracle trunc()函数的用法/**************日期********************/1.select trunc(sysdate) from dual --2013- ...

  7. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  8. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  9. 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP

    [BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...

  10. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

随机推荐

  1. 十大java应用服务器(web server)总结

    java应用服务器(web server),是指运行java程序的web应用服务器软件,不包括nginx.Apache等通用web服务器软件. 一.Tomcat Tomcat是Apache 软件基金会 ...

  2. apisix~14在自定义插件中调用proxy_rewrite

    在 Apache APISIX 中,通过 proxy-rewrite 插件来修改上游配置时,需要确保插件的执行顺序和上下文环境正确.你提到在自己的插件中调用 proxy_rewrite.rewrite ...

  3. 虚拟机安装Linux CENTOS 07 部署NET8 踩坑大全

    首先下载centos07镜像,建议使用阿里云推荐的地址: https://mirrors.aliyun.com/centos/7.9.2009/isos/x86_64/?spm=a2c6h.25603 ...

  4. 【Python】python笔记:时间模块/时间函数

    1.Python时间模块 import time import datetime # 一: time模块 ############## # 1.时间戳 print (time.time()) # 16 ...

  5. 面试官:Java对象引用都有哪些类型?

    哈喽,大家好,我是世杰. 本文我为大家介绍面试官经常考察的「Java对象引用相关内容」 照例在开头留一些面试考察内容~~ 面试连环call Java对象引用都有哪些类型? Java参数传递是值传递还是 ...

  6. 基于EF Core存储的国际化服务

    前言 .NET 官方有一个用来管理国际化资源的扩展包Microsoft.Extensions.Localization,ASP.NET Core也用这个来实现国际化功能.但是这个包的翻译数据是使用re ...

  7. P2P应用

    对等连接(peer to peer)文件分发的分析: 传统客户-服务器模式:用时与文件量成正比 P2P模式:随文件量增大而用时趋于一个极限. P2P工作方式有三: 集中式索引:客户访问服务器所需数据在 ...

  8. 万维网WWW

    万维网是一个大规模的联机式信息储存场所,能方便地从一个网络站点访问另一个网络站点.万维网是一个分布式的超媒体系统. 统一资源定位符URL URL表示从互联网上得到的资源位置和访问这些资源的方法,实际上 ...

  9. Apache Hudi X Apache Kyuubi,中国移动云湖仓一体的探索与实践

    分享嘉宾:孙方彬 中国移动云能力中心 软件开发工程师 编辑整理:Hoh Xil 出品平台:DataFunTalk 导读:在云原生 + 大数据的时代,随着业务数据量的爆炸式增长以及对高时效性的要求,云原 ...

  10. el-date-picker的value-forma在Element UI (Vue 2)和Element Plus (Vue 3)中的不同

    Element UI (Vue 2): <template> <el-form-item prop="register_date" label="成立日 ...