SMU Autumn 2024 Trial 1
A. Load Balancing
很明显题意要的就是让我们把每个数往平均值靠,这样就保证最大值-最小值最小
但是当sum%n !=0的时候就说明无法每个数都等于sum/n,所以处理的方法就是,先计算这些无法等于sum/n的个数cnt,再算出可以到达sum/n的次数n-cnt,然后算出总代价,再用总代价除以2就是答案,因为一个数的增值是由另一个数的减值来的。
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
int n,sum=0,minn=1e10,maxx=-1;
cin>>n;
vector<int>ve(n);
for(int i=0;i<n;i++){
cin>>ve[i];
sum+=ve[i];
maxx=max(maxx,ve[i]);
minn=min(minn,ve[i]);
}
if(maxx-minn<=1) {
cout<<0<<endl;
return;
}
sort(ve.rbegin(),ve.rend());//按降序排序
int cnt=sum%n,k=sum/n;
//k为向下取整后的均值
//大的向k+1靠,小的向k靠,这样保证总代价最小
int ans=0;
for(int i=0;i<n;i++)
{
if(cnt)
{
cnt--;
ans+=abs(ve[i]-k-1);
}else{
ans+=abs(ve[i]-k);
}
}
cout<<ans/2;
}
signed main()
{
int t=1;
//cin>>t;
while(t--) solve();
}
B. Longest Simple Cycle

一道比较好理解的dp

#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
int n;
cin>>n;
int f[n+1]={0};
vector<int>a(n+1),b(n+1),c(n+1);
//c存链的顶点数,b,c为连接位置
for(int i=1;i<=n;i++) cin>>c[i];
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) cin>>b[i];
for(int i=2;i<=n;i++)
{
if(a[i]==b[i]) f[i]=c[i]+1;
else{
f[i]=max(c[i]+1+f[i-1]-abs(a[i]-b[i]),c[i]+1+abs(a[i]-b[i]));
}
}
cout<<*max_element(f+1,f+n+1)<<endl;
}
signed main() {
int t;
cin >> t;
while (t--) {
solve();
}
}
C. Match Points
二分答案,枚举可以匹配的点对数,但是check里的验证,是这样的,比如 5 7 8 9 10,我枚举的mid=2,那么我要验证的是(5,9)和(7,10)这样才能确保得到的点对数最大
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int>ve;
int n,z;
bool check(int mid)
{
for(int i=1;i<=mid;i++) if(ve[n-mid+i]-ve[i]<z) return 0;
return 1;
}
void solve()
{
cin>>n>>z;
ve.resize(n+1);
for(int i=1;i<=n;i++) cin>>ve[i];
sort(ve.begin()+1,ve.end());
int l=0,r=n>>1,mid=0;//边界r不可以开太大了
int ans=0;
while(l<=r)
{
mid=(l+r)>>1;
if(check(mid)) l=mid+1,ans=mid;
else r=mid-1;
}
cout<<ans;
}
signed main()
{
int t=1;
//cin>>t;
while(t--) solve();
}
D. Vus the Cossack and a Contest
水题
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
int n,m,k;
cin>>n>>m>>k;
if(n<=min(m,k)){
cout<<"Yes";
}
else cout<<"No";
}
signed main()
{
int t=1;
//cin>>t;
while(t--) solve();
}
SMU Autumn 2024 Trial 1的更多相关文章
- Autumn is a second spring when every leaf is a flower.
Autumn is a second spring when every leaf is a flower. 秋天即是第二个春天,每片叶子都是花朵.——阿尔贝·加缪
- Visual Studio 2012 trial version
Update: vs2012.5.iso http://download.microsoft.com/download/9/F/1/9F1DEA0F-97CC-4CC4-9B4D-0DB45B8261 ...
- myeclipse trial expired[转]
转自:http://blog.csdn.net/yuyuyuyuy/article/details/5878122 今天MyEclipse提示过期了,MyEclipse Trial Expired. ...
- (转)软件版本中的Alpha,Beta,RC,Trial是什么意思?
版本号:V(Version):即版本,通常用数字表示版本号.(如:EVEREST Ultimate v4.20.1188 Beta )Build:用数字或日期标示版本号的一种方式.(如:VeryCD ...
- 软件版本中的Alpha,Beta,RC,Trial是什么意思?
版本号: V(Version):即版本,通常用数字表示版本号.(如:EVEREST Ultimate v4.20.1188 Beta ) Build:用数字或日期标示版本号的一种方式.(如:VeryC ...
- POJ 2756 Autumn is a Genius 大数加减法
Description Jiajia and Wind have a very cute daughter called Autumn. She is so clever that she can d ...
- BAYESIAN STATISTICS AND CLINICAL TRIAL CONCLUSIONS: WHY THE OPTIMSE STUDY SHOULD BE CONSIDERED POSITIVE(转)
Statistical approaches to randomised controlled trial analysis The statistical approach used in the ...
- 42028: Assignment 1 – Autumn 2019
42028: Assignment 1 – Autumn 2019 Page 1 of 4Faculty of Engineering and Information TechnologySchool ...
- PLSQL过期:Your trial period for PL/SQL Developer is over .If you want to continue using this software ,you must purchase the retail version.
PLSQL过期:Your trial period for PL/SQL Developer is over .If you want to continue using this software ...
- Remove menucool tooltip trial version
You use this crack on your own risk , i dont reserve any right on this script or what is going to af ...
随机推荐
- 深⼊mysqlONDUPLICATEKEYUPDATE语法的分析
深⼊mysqlONDUPLICATEKEYUPDATE语法的分析mysql "ON DUPLICATE KEY UPDATE" 语法如果在INSERT语句末尾指定了ON DUPLI ...
- VuePress 博客之 SEO 优化(四) Open Graph protocol
前言 在 <一篇带你用 VuePress + Github Pages 搭建博客>中,我们使用 VuePress 搭建了一个博客,最终的效果查看:TypeScript 中文文档. 本篇讲讲 ...
- java中的HsahMap
HsahMap HashMap 是 Java 中最常用的集合类之一,它实现了 Map 接口,基于哈希表存储键值对 HashMap的存储是无顺序的 HashMap存储的是键值对(key-value)其中 ...
- 基于Linux系统的PXE搭建方法
本文分享自天翼云开发者社区<基于Linux系统的PXE搭建方法>,作者:t***n 一.底层环境准备 1.安装RedHat7.6系统 2.关闭防火墙和Selinux systemctl s ...
- IDEA新建多模块maven项目
1.new =>projetc=>maven=>,新建完成后删除src目录 2.增加java模块 例:robots2-common 项目根目录就是[robots2-paren ...
- Sort operation used more than the maximum 33554432 bytes of RAM
在数据量超大的情形下,任何数据库系统在创建索引时都是一个耗时的大工程,下面这篇文章主要给大家介绍了关于MongoDB排序时内存大小限制与创建索引的注意事项的相关资料,需要的朋友可以参考下
- MySQL - [04] 分布式部署&主从复制&读写分离
一.前言 Q1:为什么需要主从复制? 1.在业务复杂的系统中,有一条SQL语句需要锁表,导致暂时不能使用读的服务,那么就很影响运行中的业务.使用主从复制,让主库负责写,从库负责读,这样即使主库出现了锁 ...
- 大模型知识引擎 LKE 新手入门指南:官方文档难懂?看这篇就够了
昨天简单体验了一下大模型知识引擎(LKE),总体来说,虽然其功能方面还有一定欠缺,但在一些特定领域,特别是RAG(Retrieval-Augmented Generation)技术的应用上,还是表现出 ...
- try except 案例
def to_split(df): # 删除不符合加班统计的记录 try: df.dropna(subset=['姓名'], inplace=True) hang_index = df[df['加班信 ...
- Visio绘制时间轴安排图的方法
本文介绍基于Visio软件绘制时间轴.日程安排图.时间进度图等的方法. 在很多学习.工作场合中,我们往往需要绘制如下所示的一些带有具体时间进度的日程安排.工作流程.项目进展等可视化图表. ...