SMU Summer 2024 Contest Round 3

A.Hcode OnlineJudge

 先用欧拉筛把质数预处理出来,然后枚举左端点的质数,只需要询问右端点是不是质数并取差值的min就行了

#include<bits/stdc++.h>
#define endl '\n'
#define mk make_pair
#define int long long
using namespace std;
typedef long long ll; 
typedef pair<int, int> PII; 
const int N = 1e6+10;
int n,m,k;vector<int>pri;
bool su[10005];void get(){for(int i=2;i<=10000;i++){if(!su[i]) pri.push_back(i);for(auto ed:pri){if(i*ed>10005) break;su[ed*i]=1;if(i%ed==0) {break;}}}
}void sovle(){get();while(scanf("%d",&n)!=EOF){int ans1=0,ans2=0,num=1000000;for(auto ed:pri){if(!su[abs(n-ed)]){int vd=abs(n-ed);if(abs(ed-vd)<num){num=abs(ed-vd);ans1=min(ed,vd);ans2=max(ed,vd);}}}cout<<ans1<<" "<<ans2<<endl;}
}signed main()
{	//ios::sync_with_stdio(false), cin.tie(0),cout.tie(0); int t = 1; //cin>>t;while (t --){sovle();}return 0;
}

B.Hcode OnlineJudge

 随便模拟一下就找到规律了(被多组数据狠狠教育了

#include<bits/stdc++.h>
#define endl '\n'
#define mk make_pair
#define int long long
using namespace std;
typedef long long ll; 
typedef pair<int, int> PII; 
const int N = 1e6+10;
int n,m,k;void sovle(){while(scanf("%d %d",&n,&m)){if(!n&&!m) return;cout<<n+m-2<<endl;}
}signed main()
{	ios::sync_with_stdio(false), cin.tie(0),cout.tie(0); int t = 1; //cin>>t;while (t --){sovle();}return 0;
}

C.Hcode OnlineJudge

 要使疲劳度最小,必然要找k组相邻的最小差值对,考虑n方的dp,i,j表示前i个物品取k对,注意考虑怎么初始化

#include<bits/stdc++.h>
#define endl '\n'
#define mk make_pair
#define int long long
using namespace std;
typedef long long ll; 
typedef pair<int, int> PII; 
const int N = 1e6+10;
const int inf = 0x3f3f3f3f;
int n,m,k;int f(int x,int y){return (x-y)*(x-y);
}void sovle(){while(cin>>n>>k){int a[n+1];for(int i=1;i<=n;i++) cin>>a[i];sort(a+1,a+n+1);int dp[n+1][k+1];for(int i=0;i<=n;i++){for(int j=0;j<=k;j++){if(i==0||j==0) dp[i][j]=0;else dp[i][j]=inf;}}for(int i=2;i<=n;i++){for(int j=1;j*2<=i&&j<=k;j++){dp[i][j]=min(dp[i-1][j],dp[i-2][j-1]+f(a[i-1],a[i]));}}cout<<dp[n][k]<<endl;}
}signed main()
{	ios::sync_with_stdio(false), cin.tie(0),cout.tie(0); int t = 1; //cin>>t;while (t --){sovle();}return 0;
}

D.Hcode OnlineJudge

水题

#include<bits/stdc++.h>
#define endl '\n'
#define mk make_pair
#define int long long
using namespace std;
typedef long long ll; 
typedef pair<int, int> PII; 
const int N = 1e6+10;
int n,m,k;void sovle(){int sum=0;cin>>n;vector<int>a(n);for(int i=0;i<n;i++) {cin>>a[i];if(a[i]>10) sum+=a[i]-10;}cout<<sum<<endl;
}signed main()
{	ios::sync_with_stdio(false), cin.tie(0),cout.tie(0); int t = 1; //cin>>t;while (t --){sovle();}return 0;
}

F.Hcode OnlineJudge

对于每组,只有取左边或者右边,等同于对左边,取或者不取。数据范围很小,二进制枚举秒了

#include<bits/stdc++.h>
#define endl '\n'
#define mk make_pair
#define int long long
using namespace std;
typedef long long ll; 
typedef pair<int, int> PII; 
const int N = 1e6+10;
int n,m,k;void sovle(){cin>>n>>m;vector<int>a(m),b(m);for(int i=0;i<m;i++) cin>>a[i]>>b[i];cin>>k;vector<int>c(k),d(k);int max1=-1;for(int i=0;i<k;i++) cin>>c[i]>>d[i];for(int i=0;i<(1<<k);i++){map<int,int>v,x;for(int j=0;j<k;j++){if((i>>j)&1){v[c[j]]=1;}else{v[d[j]]=1;}}int sum=0;for(int i=0;i<m;i++){if(v[a[i]]&&v[b[i]]){sum++;}}max1=max(max1,sum);}cout<<max1<<endl;
}signed main()
{	ios::sync_with_stdio(false), cin.tie(0),cout.tie(0); int t = 1; //cin>>t;while (t --){sovle();}return 0;
}

I.Hcode OnlineJudge

 给一个小于1e18的正整数,询问能否通过删除最少的位数让该数被3整除。类似的,二进制枚举当前位数删或者不删

#include<bits/stdc++.h>
#define endl '\n'
#define mk make_pair
#define int long long
using namespace std;
typedef long long ll; 
typedef pair<int, int> PII; 
const int N = 1e6+10;
int n,m,k;void sovle(){string s;cin>>s;int n=s.size();int num=-1;for(int i=0;i<(1<<n);i++){map<int,int>v;for(int j=0;j<n;j++){if((i>>j)&1){v[j]=1;}}int u=0;int x=1;int sum=0;for(int i=n-1;i>=0;i--){if(v[n-1-i]) {sum++;continue;}u+=x*(s[i]-'0');x*=10;}if(u%3==0&&u){if(num==-1) num=sum;else num=min(sum,num);}}cout<<num<<endl;
}signed main()
{	ios::sync_with_stdio(false), cin.tie(0),cout.tie(0); int t = 1; //cin>>t;while (t --){sovle();}return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/869783.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

深入解析 Laravel 策略路由:提高应用安全性与灵活性的利器

引言 Laravel 是一个功能强大的 PHP Web 应用框架&#xff0c;以其优雅和简洁的语法而受到开发者的喜爱。在 Laravel 中&#xff0c;路由是应用中非常重要的一部分&#xff0c;它负责将用户的请求映射到相应的控制器方法上。Laravel 提供了多种路由方式&#xff0c;其中策略路…

NodeJS小饰品销售管理系统-计算机毕业设计源码21597

摘 要 在当今的数字化时代&#xff0c;电子商务已经成为了商业领域中不可或缺的一部分。随着消费者对于购物体验的要求越来越高&#xff0c;一个高效、便捷、用户友好的小饰品销售管理系统显得尤为重要。 本系统旨在利用 JavaScript 技术&#xff0c;设计并实现一个功能强大的小…

conda篇----在已有conda环境的基础上升级python包

conda篇----在已有conda环境的基础上升级python包 原先的python版本 第一步&#xff1a; conda update --all(py11) [xxxaivrs01 xxx]$ conda update --all Collecting package metadata (current_repodata.json): done Solving environment: done> WARNING: A newer vers…

如何高效学习(二)

二、如何练就超强学习能力&#xff1f;为什么有的人学的又快又好&#xff1f;高效学习的底层逻辑在这&#xff01; 说实话看到这个标题我感觉我捡到宝了&#xff0c;这不就是我一直在找寻的吗 这一节视频他分了三部分&#xff0c;分别是取势篇、明道篇、优术篇还有每次都有的&q…

【读点论文】ASAM: Boosting Segment Anything Model with Adversarial Tuning,对抗学习提升性能

ASAM: Boosting Segment Anything Model with Adversarial Tuning Abstract 在不断发展的计算机视觉领域&#xff0c;基础模型已成为关键工具&#xff0c;对各种任务表现出卓越的适应性。其中&#xff0c;Meta AI 的 Segment Anything Model (SAM) 在图像分割方面表现突出。然…

C语言 输出图案

输出以下图案: * * * * * * * * * * * * * * * * * * * * * * * * * #include <stdio.h>int main() {int n 5;for (int i 0; i < n; i) {for (int j 0; j < i; j) {printf(" ");}for (int k 0; k < n; k) {printf("* ");}pr…

首批!蚂蚁数科通过中国信通院面向大模型的可信执行环境产品专项测试

2024年6月17日&#xff0c;在中国信息通信研究院&#xff08;以下简称“信通院”&#xff09;组织的首批“面向大模型的增强型可信执行环境基础能力专项测试”中&#xff0c;蚂蚁数科摩斯顺利完成全部测试内容&#xff0c;成为首批完成此项测试的组织。 标准及测试介绍 《面向…

全局唯一id

问题引出&#xff1a; 由于数据库的自增的id很有规律&#xff0c;会让人猜到后续id 由于一个单表存储的数量有限&#xff0c;那么就会用多个表存储&#xff0c;每个表的id都是自增&#xff0c;这样导致id不唯一的情况。 引进新的方法&#xff1a; 具体解决方法&#xff1a;使用…

MySQL--函数、约束、多表查询

函数 函数指一段可以直接被另一段程序调用的程序或代码 字符串函数、数值函数、日期函数、流程函数 字符串函数 数值函数 日期函数 datediff&#xff08;date1,date2&#xff09;&#xff1a;date1-date2 流程函数 约束 概念&#xff1a;约束是作用于表中字段上的规则&…

ECCV:A Discriminative Feature Learning Approach for Deep Face Recognition

1 Abstract 卷积神经网络&#xff08;CNNs&#xff09;已广泛应用于计算机视觉领域&#xff0c;显著提高了计算机视觉领域的技术水平。在大多数可用的cnn中&#xff0c;使用软tmax损失函数作为监督信号来训练深度模型。为了增强深度学习特征的识别能力&#xff0c;本文提出了一…

AI自动生成PPT怎么用?5种提升演示效果的方法

随着#7月份我的同事一个个消失了#的话题热议&#xff0c;职场中的效率与变革再次成为焦点。 在忙碌的工作节奏中&#xff0c;AI自动生成PPT的软件悄然兴起&#xff0c;成为不少职场人的新宠。它们不仅简化了繁琐的PPT制作流程&#xff0c;更以高效、专业的姿态&#xff0c;助力…

包成功安装tiny-cuda-nn,记录安装过程中的问题解决,附带pytorch3d安装【踩坑指南】

tiny-cuda-nn安装过程中的问题解决&#xff0c;附带pytorch3d安装【踩坑指南】 前言tiny-cuda-nn第一种下载方法&#xff1a;命令行安装tiny-cuda-nn第二种下载方法&#xff1a;本地编译 pytorch3d安装 前言 official repo: https://github.com/NVlabs/tiny-cuda-nn 该包可以显…

Java 中的阻塞 IO 和非阻塞 IO

Java 中的阻塞 IO 和非阻塞 IO 1、阻塞 IO&#xff08;Blocking IO&#xff09;2、非阻塞 IO&#xff08;Non-blocking IO&#xff09;3、区别与应用场景4、总结 &#x1f496;The Begin&#x1f496;点点关注&#xff0c;收藏不迷路&#x1f496; IO&#xff08;输入输出&…

C语言从头学32——字符串数组

关于字符串数组的声明方式&#xff0c;介绍两种&#xff1a; 1、二维数组方式 如果一个数组的每个成员本身也是字符串&#xff0c;那就需要通过二维的字符数组来表示。每个字符串本身是一个字符数组&#xff0c;多个字符串再组成一个数组。如下例&#xff1a; ch…

基于Booth乘法和Wallace树的乘法器优化思想

基于Booth乘法和Wallace树的快速乘法器 为了理解Booth乘法和Wallace数如何让乘法器变得更快&#xff1a; 先考虑不优化的8位乘法器实现&#xff0c;即8个16位数字累积共进行7次加法运算&#xff0c;可以认为一次16位加法用到16个全加器&#xff0c;则共需要112个全加器件&…

字节面试题:在线表格功能怎么实现?怎么测?

最近有小伙伴私信问我怎么不更新了&#xff0c;期待更新&#xff0c;甚是感动。 简述下自己近况&#xff1a; 还在干测试&#xff0c;最近忙活的事情大概是自动化测试、性能测试以及业务等等&#xff0c;主打一个啥活都干。 业余时间&#xff0c;尝试在短视频赛道搞一些个人兴…

【Linux操作系统-测试】第三节.Linux 系统、网络信息、用户权限命令总结

文章目录 前言一、Linux 系统相关信息命令 1.1 df 命令--查看磁盘剩余 1.2 ps 命令--查看进程 1.3 top 命令--显示进程运行状态 1.4 kill 命令说明 -- 杀死进程二、Linux 网络信息命令 2.1 ping 命令--检查网络是否连通 2.1 ifconfig--显示网络设…

(总结)编译ORB_SLAM2遇到的错误

目录 第一个错误error: ‘CV_BGR2GRAY’ was not declared in this scope 第二个错误error: ‘CV_GRAY2BGR’ was not declared in this scope 第三个错误是没有那个文件或目录 26 | #include 第四个错误是‘CV_LOAD_IMAGE_UNCHANGED’ was not declared in this scope 第…

Python实现的深度学习技术在水文水质领域应用

当前&#xff0c;深度学习作为人工智能的热门技术发展迅速&#xff0c;以其强大的非线性和不确定性处理能力在图像识别、语音识别、自然语言处理等领域取得了显著的成效。它是一种端到端的处理方法&#xff0c;在训练算法的指导下&#xff0c;深层神经网络自发地从原始数据中进…

什么是CAP理论及应用场景,为什么只能进行3选2

在理论计算机科学中&#xff0c;CAP定理&#xff08;CAP theorem&#xff09;&#xff0c;又被称作布鲁尔定理&#xff08;Brewers theorem&#xff09;&#xff0c;它指出对于一个分布式计算系统来说&#xff0c;不可能同时满足以下三点&#xff1a; 1、 一致性&#xff08;C…