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的更多相关文章

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

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

  3. Codeforces Round #539 (Div. 2)

    Codeforces Round #539 (Div. 2) A - Sasha and His Trip #include<bits/stdc++.h> #include<iost ...

  4. Codeforces Round #539 (Div. 2) 题解

    Codeforces Round #539 (Div. 2) 题目链接:https://codeforces.com/contest/1113 A. Sasha and His Trip 题意: n个 ...

  5. Codeforces Round #539 Div1 题解

    Codeforces Round #539 Div1 题解 听说这场很适合上分QwQ 然而太晚了QaQ A. Sasha and a Bit of Relax 翻译 有一个长度为\(n\)的数组,问有 ...

  6. Codeforces Round #539&#542&#543&#545 (Div. 1) 简要题解

    Codeforces Round #539 (Div. 1) A. Sasha and a Bit of Relax description 给一个序列\(a_i\),求有多少长度为偶数的区间\([l ...

  7. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

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

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

随机推荐

  1. Oracle 查询合并列

    在ORACLE  查询时,有时要将多个列合并成一行,其方法如下: 1. decode 函数 decode 函数的语法为: decode(条件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省 ...

  2. qt4 看不到qstring内容

    qt4: https://gist.github.com/gregseth/9bcd0112f8492fa7bfe7

  3. python:选房抽签小工具

    1.房间号和姓名写在house_name.xls的house标签页中[注意!名字均不要改动]2.运行house.py3.当前同目录下会生成result.xls,即为结果:程序运行过程中不要打开该文件, ...

  4. leetcode300

    本题使用回溯法,深度优先搜索.使用隐式条件来进行加速. public class Solution { ; int[] x; Dictionary<int, int> dic = new ...

  5. 并发中的volatile

    目录 1. 概述 2. volatile的特性 3. volatile写-读的内存语义 4. volatile内存语义的实现 5. JSR-133为什么要增强volatile的内存语义 6. 总结 1 ...

  6. Vue.js连接后台数据jsp页面  ̄▽ ̄

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  7. wget 网站扒取

    wget --mirror --page-requisites --adjust-extension --no-parent --convert-links  http://target.com

  8. HashMap负载因子为什么是0.75

    待写 HashMap负载因子为什么是0.75?HashMap有一个初始容量大小,默认是16static final int DEAFULT_INITIAL_CAPACITY = 1 << ...

  9. springboot整合zookeeper

    在springboot中所有的整合都是以bean的形式注入对象,从数据库coon.redis conn.再到整合的zookeeper,依然是依照bean注入连接对象,通过zookeeper api对z ...

  10. Blender Python脚本的6个技巧

    https://www.youtube.com/watch?v=vFoh3S8MLBI&index=3&list=PLw8Sjaw0TPm0J9DXj3XGi1_9fxXezlzrM ...