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 ...
随机推荐
- python3 json.dump乱码问题
json.dumps(obj, ensure_ascii=False) ensure_ascii = True,会忽略掉non-ascii字符
- 基于LNMP的Zabbix4.0.1部署
转:http://www.safecdn.cn/monitor/2018/12/lnmp-zabbix4-0-1-install/306.htmlZabbix4.0.1部署 一 安装源和Zabb ...
- Docker 安装 oracle 并使用 navicat 实现外部连接
1,拉取 docker 镜像:docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g 1.1 , 该镜像由阿里云提供,比较大, ...
- javascript权威指南第1章Js概述js语言核心
<html> <head> <script> function Point(x,y){ this.x=x; this.y=y; } ,); console.log( ...
- 转 java的JsonObject对象提取值
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson ...
- css之标签选择器
标签(空格分隔): 标签选择器 选择器定义: 在一个HTML页面中会有很多很多的元素,不同的元素可能会有不同的样式,某些元素又需要设置相同的样式,选择器就是用来从HTML页面中查找特定元素的,找到元素 ...
- Ubuntu 装nexus
装nexus前提是装好JDK和maven 先下载 wget http://download.sonatype.com/nexus/oss/nexus-2.12.0-01-bundle.tar.gz 再 ...
- [leetcode]51. N-QueensN皇后
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens ...
- Python爬虫项目--爬取链家热门城市新房
本次实战是利用爬虫爬取链家的新房(声明: 内容仅用于学习交流, 请勿用作商业用途) 环境 win8, python 3.7, pycharm 正文 1. 目标网站分析 通过分析, 找出相关url, 确 ...
- Pycharm中选择Python解释器
新建项目后,有时候Pycharm找不到Python解释器,如果找不到的话,就会报错.报错信息: No python interpreter configured for the project 找到P ...