SMU Autumn 2023 Round 1(Div.1)

A. Set or Decrease(枚举)

题意就是你可以进行两种操作,将\(a_i-1\)或者令\(a_i\)等于\(a_j\),然后使得\(\sum\limits_{i=1}^{n}a_i \leq k\),求最少的操作步数

首先我们让一个大数变成一个最小数的贡献肯定是要比让大数减一产生的贡献更多,所以我们可以排序后去枚举将后面\(i\)个数变成最小数后得到的和\(Sum\)来与\(k\)比较,求和可以用前面\((n-i-1)\)个数的前缀和加上后面\(i\)个最小数,即\(a_0\),如果这个和仍然大于\(k\),那我们就要执行减一操作了,因为后面的大数都等于最小数了,所以这个减一操作也是只有最小数减一才能贡献最大,至于要减多少,那就是\(\lceil \frac{Sum-k}{i} \rceil\),即将这个差值平均分到后面的\(i\)个数中,且\(Sum \leq k\),所以我们一定得向上取整,每次的步数即\(i+\lceil \frac{Sum-k}{i} \rceil\),然后取最小值即可

#include <bits/stdc++.h>
#define int long long
#define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std; void solve() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (auto &i : a)
cin >> i; sort(a.begin(), a.end());
vector<int> num(n);
num[0] = a[0];
for(int i = 1;i < n;i ++)
num[i] = num[i - 1] + a[i]; int ans = 1e15;
for(int i = 0;i < n;i ++){
int s = num[n - i - 1] + a[0] * i;
int t = i;
if(s > k){
t += (s - k + i) / (i + 1);
}
ans = min(ans, t);
} cout << ans << '\n'; } signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int T;
cin >> T;
while (T--) {
solve();
} return 0;
}

E. Exact Change(暴力枚举)

题意就是用面值为\(1,2,3\)的三种纸币去凑出\(n\)个数,且要让使用的纸币数最少

首先肯定是尽量的去使用面值为\(3\)的纸币,面值为\(1\)的最多使用\(1\)张,再多就可以用纸币\(2\)或\(3\)代替,纸币\(2\)最多使用\(2\)张,\(3\)张纸币\(2\)可以用\(2\)张纸币\(3\)代替,数据范围较小,可以直接去暴力枚举使用纸币\(1\)和纸币\(2\)的数量,然后去找出当使用\(i\)张纸币\(1,j\)张纸币\(2\)时使得所有数能凑出的纸币\(3\)最大所需要的数量\((res)\),则总使用张数为\((res + i+j)\),然后在枚举\(i,j\)的过程中判断一下最小值就行了

#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std;
using i64 = long long; int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int T;
cin >> T;
while (T--) {
int n;
cin >> n;
vector<int> a(n);
for (auto &i : a) cin >> i; i64 ans = INT_MAX;
for (int i = 0; i <= 1; i ++) {
for (int j = 0; j <= 2; j ++) {
i64 res = 0;
for (auto ai : a) {
i64 v3 = INT_MAX;
for (int x1 = 0; x1 <= i; x1 ++) {
for (int x2 = 0; x2 <= j; x2 ++) {
i64 ak = ai - x1 - 2 * x2;
if (ak >= 0 && ak % 3 == 0)
v3 = min(v3, ak / 3);
}
}
res = max(res, v3);
}
ans = min(ans, res + i + j);
}
} cout << ans << '\n'; } return 0;
}

F. Replace the Numbers(离线)

题意是给出两种操作,操作\(1\)是在序列后添加一个数,操作\(2\)是将序列中的\(x\)都替换成\(y\),问\(q\)次操作后的序列

可以发现的是,每一步操作\(2\)都会影响这一步之前的序列,如果暴力做的话就需要每次都循环一遍之前的序列,但如果我们反过来看,从最后一步往前的话,那么每一步操作\(2\)影响的就是之后的序列了,假设\(f_x \rightarrow x, f_y \rightarrow y\),遇到操作\(1\)的话,直接加上对应的值即可,遇到操作\(2\)的话,就要让\(f_x \rightarrow f_y\),而不能直接让\(f_x \rightarrow y\),因为\(y\)之后还可能已经变成其他值了,如\(f_y \rightarrow z\),那么这一步应该是\(f_x \rightarrow f_y \rightarrow z\),之后又遇到操作\(1\),直接加上\(f_x \rightarrow \dots \rightarrow z\)即可,因为是从后往前操作的,所以最后输出要倒序输出

#include <bits/stdc++.h>
#define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std;
using i64 = long long; int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int q;
cin >> q;
vector<int> f(500005),opt(q + 1),x(q + 1),y(q + 1);
iota(f.begin(), f.end(),0); for(int i = 1;i <= q;i ++){
cin >> opt[i];
if(opt[i] == 1)
cin >> x[i];
else
cin >> x[i] >> y[i];
} vector<int> ans(q + 1);
int l = 0;
for(int i = q;i >= 1;i --){
if(opt[i] == 1)
ans[++l] = f[x[i]];
else
f[x[i]] = f[y[i]];
} for(int i = l;i >= 1;i --)
cout << ans[i] << ' '; return 0;
}

G. Triangles on a Rectangle

题意是给你一个矩形,然后四条边每条边至少有两个点,然后在这个矩形中选三个点使得组成的三角形面积最大

画个图其实就能看出了

就是找每条边上最远的两点和长或宽作为高组成的三角形最大的即可

#include <bits/stdc++.h>
#define int long long using namespace std; void solve() {
int w, h;
cin >> w >> h;
int ans = 0;
int k, x;
cin >> k;
int ma = 0, mi = 1e7;
for (int i = 0; i < k; i ++) {
cin >> x;
mi = min(x, mi);
ma = max(ma, x);
}
ans = (ma - mi) * h;
cin >> k;
ma = 0, mi = 1e7;
for (int i = 0; i < k; i ++) {
cin >> x;
mi = min(x, mi);
ma = max(ma, x);
}
ans = max(ans, (ma - mi) * h);
cin >> k;
ma = 0, mi = 1e7;
for (int i = 0; i < k; i ++) {
cin >> x;
mi = min(x, mi);
ma = max(ma, x);
}
ans = max(ans, (ma - mi) * w);
cin >> k;
ma = 0, mi = 1e7;
for (int i = 0; i < k; i ++) {
cin >> x;
mi = min(x, mi);
ma = max(ma, x);
}
ans = max(ans, (ma - mi) * w);
cout << ans << '\n';
} signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); int T;
cin >> T;
while (T--) {
solve();
}
return 0;
}

SMU Autumn 2023 Round 1(Div.1)的更多相关文章

  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. 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 ...

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

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

  4. Codeforces Round #368 (Div. 2)

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

  5. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  6. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  7. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  8. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

  9. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  10. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

随机推荐

  1. MongoDB文档存储

    非关系型数据库存储 NoSQL,全称 Not Only SQL,意为不仅仅是 SQL,泛指非关系型数据库.NoSQL 是基于键值对的,而且不需要经过 SQL 层的解析,数据之间没有耦合性,性能非常高. ...

  2. JS神奇的或0(|0)

    按照常识,位运算x|0,要么等于x,要么等于0 那么在JS的世界你的认知就要被颠覆了 下面请看 不带或0运算: (window.crypto.getRandomValues(new Uint32Arr ...

  3. C#使用RegNotifyChangeKeyValue监听注册表更改的几种方式

    养成一个好习惯,调用 Windows API 之前一定要先看文档 RegNotifyChangeKeyValue 函数 (winreg.h) - Win32 apps | Microsoft Lear ...

  4. OpenLiveWriter的代码高亮插件

    可参考如下方法: https://www.cnblogs.com/mq0036/p/12101912.html 0. 最新插件下载地址:Memento.OLW_V1.0.0.5.7z 1. 找到Ope ...

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

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

  6. USB 协议学习:000-有关概念

    USB 协议学习:000-有关概念 背景 USB作为一种串行接口,应用非常广泛.掌握usb也是作为嵌入式工程师的一项具体要求. 概述 USB( Universal Serial Bus, 通用串行总线 ...

  7. 下载 Linux 内核的脚本

    介绍 在 类UNIX 环境下运行比较好(基于wget) 包括了 2.6 ~ 4.x 内核的地址. 5.x 因为 还在更新因此不做记录. 脚本下载地址: https://files.cnblogs.co ...

  8. 可重入锁思想,设计MQ迁移方案

    如果你的MQ消息要从Kafka切换到RocketMQ且不停机,怎么做?在让这个MQ消息调用第三方发奖接口,但无幂等字段又怎么处理?今天小傅哥就给大家分享一个关于MQ消息在这样的场景中的处理手段. 这是 ...

  9. 光伏储能电厂设备连接iec61850平台解决方案

    在当今日益发展的电力系统中,光伏储能技术以其独特的优势逐渐崭露头角,成为可再生能源领域的重要组成部分.而在光伏储能系统的运行与监控中,通信协议的选择与实现则显得至关重要.本文将重点介绍光伏储能系统中的 ...

  10. c 语言学习第四天

    if 语句 格式: // 1 // 其他语句... if(表达式){ // 其他语句... } // 其他语句... // 2 if(表达式){ }else{ } // 3 if(表达式1){ }el ...