Codeforces Round #539--1113B - Sasha and Magnetic Machines
https://codeforces.com/contest/1113/problem/B
思想不难,但是在比较大小的时候,我选择了很笨的方法,我用两个数变化之后的差值大小来进行选择,然后最后再进行数组的更改,最后求和。
实际上,可以先求和,在每次运算之前,减去两个数,然后再把处理后的两个数加上,比较和的大小。
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> num;
vector<int> isPrime(int d){
vector<int> res;
for(int i=;i*i<=d;i++){
if(d%i==){
res.push_back(i);
if(i!=d/i)
res.push_back(d/i);
}
}
return res;
}
int main(){
cin>>n;
num.resize(n);
for(int i=;i<n;i++)
cin>>num[i];
int sum=accumulate(num.begin(),num.end(),);
int minNum=*min_element(num.begin(),num.end());
int ress=sum;
for(int i=;i<num.size();i++){
vector<int> res=isPrime(num[i]);
for(int j=;j<res.size();j++){
int c=res[j];
int tmpSum=sum-minNum-num[i];
tmpSum+=minNum*c+num[i]/c;
ress=min(ress,tmpSum);
}
}
cout<<ress<<endl;
return ;
}
Codeforces Round #539--1113B - Sasha and Magnetic Machines的更多相关文章
- Codeforces Round #539 (Div. 2) - D. Sasha and One More Name(思维)
Problem Codeforces Round #539 (Div. 2) - D. Sasha and One More Name Time Limit: 1000 mSec Problem ...
- Codeforces Round #539 (Div. 2) - C. Sasha and a Bit of Relax(思维题)
Problem Codeforces Round #539 (Div. 2) - C. Sasha and a Bit of Relax Time Limit: 2000 mSec Problem ...
- Codeforces Round #539 (Div. 2)
Codeforces Round #539 (Div. 2) A - Sasha and His Trip #include<bits/stdc++.h> #include<iost ...
- Codeforces Round #539 (Div. 2) 题解
Codeforces Round #539 (Div. 2) 题目链接:https://codeforces.com/contest/1113 A. Sasha and His Trip 题意: n个 ...
- Codeforces Round #539 Div1 题解
Codeforces Round #539 Div1 题解 听说这场很适合上分QwQ 然而太晚了QaQ A. Sasha and a Bit of Relax 翻译 有一个长度为\(n\)的数组,问有 ...
- Codeforces Round #539Ȟȟȡ (Div. 1) 简要题解
Codeforces Round #539 (Div. 1) A. Sasha and a Bit of Relax description 给一个序列\(a_i\),求有多少长度为偶数的区间\([l ...
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- Codeforces Round #539 (Div. 2) C. Sasha and a Bit of Relax(前缀异或和)
转载自:https://blog.csdn.net/Charles_Zaqdt/article/details/87522917 题目链接:https://codeforces.com/contest ...
- Codeforces Round #539 (Div. 2) C Sasha and a Bit of Relax
题中意思显而易见,即求满足al⊕al+1⊕…⊕amid=amid+1⊕amid+2⊕…⊕ar且l到r的区间长为偶数的这样的数对(l,r)的个数. 若al⊕al+1⊕…⊕amid=amid+1⊕amid ...
随机推荐
- 2-zookeeper、ha
1.zookeeper ①背景: Zookeeper 最早起源于雅虎研究院的一个研究小组.在当时,研究人员发现,在雅虎内部很多大型系统基本都需要依赖一个类似的系统来进行分布式协调, 但是这些系统往往都 ...
- 学习笔记:SASS
SASS: http://www.sass.hk/sass-course.html SASS 2015-10-10 http://sass.bootcss.com/docs/sass-referen ...
- itextsharp图片生成pdf模糊问题解释
I forget to mention that I' am using itextsharp 5.0.2. It turned out that PDF DPI = 110, which means ...
- Python学习:模块初识、数据类型
1.模块初识 在Python中,模块分为两种: (1)标准库 标准库无需安装,只要在使用的时候import就可以使用了 (2)第三方库 第三方库必须下载安装之后才能够引入使用 下面介绍两个基本的模块: ...
- ArcGIS自定义工具箱-字段分割
ArcGIS自定义工具箱-字段分割 联系方式:谢老师,135-4855-4328,xiexiaokui#qq.com 目的:用指定分割符分割字段, 用例:湖南省长沙市=>湖南/长沙 数据源: 使 ...
- CSS 表单
输入框前有图片 老板让你实现在输入框前有图片的功能.老板觉得用图片代替文字更有说服力. 要实现这样的功能很简单,它的原理是将图片放在内边距内. 代码 1 2 3 4 5 6 7 8 9 10 11 1 ...
- C++ queue
queuequeue 模板类的定义在<queue>头文件中.与stack 模板类很相似,queue 模板类也需要两个模板参数,一个是元素类型,一个容器类型,元素类型是必要的,容器类型是可选 ...
- 在网站中使用UEditor富文本编辑器
UEditor是由百度WEB前端研发部开发的所见即所得的开源富文本编辑器,具有轻量.可定制.用户体验优秀等特点. 官网链接 进入到下载页面,选择相应的版本下载 这里我们使用ASP.NET开发,所以选择 ...
- php curl抓取类分享
class UsualFunForNetWorkHelper { /*** * post请求数据 */ public static function HttpsPost($url, $data = n ...
- [leetcode]42. Trapping Rain Water雨水积水问题
Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...