【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
【链接】h在这里写链接
【题意】
【题解】
sum[R-1]-sum[R-x/y-1];
【错的次数】
【反思】
【代码】
/*
所有数字都等于1
①把n-1个数字删掉,剩下一个数字,再递增1? (n-1)*x + y = n*x + y - x
②或者,把n个数字都加上1,花费为n*y
n*x + y - x > n*y
n*x - n*y > x - y;
n*(x-y) > (x-y)
如果x > y
选第二种
如果x < y
选第一种
但是,也可以其中一些数字加上1,剩下的全删掉.
一个数字加上1之后,就不用删掉了.
所以,哪一个花费比较低,就优先操作那一个就好.
那最后如果全是选删掉怎么办?
那就只能留一个选增加了。
枚举最后的gcd为i.
然后如果一个数字比它小的话,就看一下加的费用和删的费用,哪一个比较大。
选那个费用比较小的。
然后选取费用差值最小的那个,以防全都被删掉了。
O(N^2)的复杂度了
比i小的数字,肯定是要删掉的->不一定,可以加到gcd.
但加到一定程度,就一定要删掉的。
因为删掉的花费不变,但是你一直增加,花费是会变多的。
但是也不一定能被i整除,整体的gcd就是i啊
give up. */ #include <bits/stdc++.h>
using namespace std; const int N = 2e6; int n;
long long num[N+10], sum[N+10],x,y,ans = -1; void inandpre() {
cin >> n >> x >> y;
for (int i = 1; i <= n; i++) {
int t;
cin >> t;
num[t]++, sum[t] += t;
} for (int i = 1; i <= N; i++)
sum[i] += sum[i - 1],num[i]+=num[i-1];
} const int M = 1e6;
bool iszs[M + 10];
vector <int> zsb;
void getzhishu() {
memset(iszs, true,sizeof iszs);
for (int i = 2; i <= M; i++){
if (iszs[i]) zsb.push_back(i);
int len = zsb.size();
for (int j = 0; j <= len - 1; j++) {
int t = zsb[j];
if (i*t > M) break;
iszs[i*t] = false;
if (i%t == 0) break;
}
}
} void meiju() {
for (int ii = 0; ii <= (int) zsb.size()-1; ii++) {
long long rest = 0;
int i = zsb[ii];
for (int j = i; j <= N; j += i) {
long long temp = x / y;
long long ju = j - temp,l = j-i+1,r = j;
ju = max(ju, l);
rest += x*(num[ju-1] - num[l - 1]);//删掉
rest += y*((num[r - 1] - num[ju - 1])*r - (sum[r-1]-sum[ju-1]));//加上
}
if (ans == -1)
ans = rest;
else
ans = min(ans, rest);
}
} void out() {
cout << ans << endl;
} int main() {
//freopen("F:\\rush.txt", "r", stdin);
ios::sync_with_stdio(0);
inandpre();
getzhishu();
meiju();
out();
return 0;
}
【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers的更多相关文章
- 【Codeforces Round #432 (Div. 2) A】 Arpa and a research in Mexican wave
[链接]h在这里写链接 [题意] 在这里写题意 [题解] t<=k,输出t t>=n,输出k-t+n 其他情况都是k [错的次数] 0 [反思] 在这了写反思 [代码] /* */ #in ...
- 【Codeforces Round #432 (Div. 2) B】Arpa and an exam about geometry
[链接]h在这里写链接 [题意] 给你3个点A,B,C 问你能不能将纸绕着坐标轴上的一点旋转.使得A与B重合,B与C重合 [题解] 这3个点必须共圆. 则A,B,C不能为一条直线.否则无解. 共圆之后 ...
- 【Codeforces Round #432 (Div. 1) A】 Five Dimensional Points
[链接]点击打开链接 [题意] 给你n个5维的点. 然后让你以其中的某一个点作为起点a. 另选两个点b,c. 组成向量a->b,a->c 如果所有的a->b和a->c的夹角都是 ...
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
- 【Codeforces Round #423 (Div. 2) B】Black Square
[Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...
- 【Codeforces Round #423 (Div. 2) A】Restaurant Tables
[Link]:http://codeforces.com/contest/828/problem/A [Description] 有n个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个 ...
随机推荐
- [Servlet]研究ServletContext对象
作者信息 作者姓名:金云龙 个人站点:http://www.longestory.com 个人公众帐号:搜索"longestory"或"龙哥有话说" Servl ...
- 闲的无聊写了个很(wu)有(liao)意(dao)思(bao)的程序
下午机房断网了 闲的无聊,写了个小游戏 忘了sleep在哪个库里了.. 自带变色效果哦 #include<iostream> #include<cstdio> #include ...
- javafx clipboard
public class EffectTest extends Application { public static void main(String[] args) { launch(args); ...
- ajax处理响应(三)
一旦脚本调用了send方法,浏览器就会在后台发送请求到浏览器.因为请求是在后台处理的,所以Ajax依靠事件来通知你这个请求的进度的进展情况,在上个随笔的里,使用handleResponse函数 ...
- 常用的130个vim命令
最近VIM用的也越来越多了...因为确实在慢慢的把win下的编辑习惯转成unix下的编辑习惯..._vimrc也在不断的完善中先贴一下平时在VIM中使用中的命令...有很多也是我没有掌握的 (估计也是 ...
- Python day4知识回顾
# -*- coding: utf_8 _*_# Author:Vi#字典是无序的 info = { 'student001':"DIO", 'student002':" ...
- git把本地文件上传到github上的步骤
1.清除clean 2.返回上一级cd .. 3.克隆仓库地址git clone+地址 4.添加忽悠文件vim .gitignore 5查看cat .gitignore 6.进入到test,并且添加所 ...
- C#引用c++DLL结构体数组注意事项(数据发送与接收时)
本文转载自:http://blog.csdn.net/lhs198541/article/details/7593045 最近做的项目,需要在C# 中调用C++ 写的DLL,因为C# 默认的编码方式是 ...
- 【Educational Codeforces Round 36 B】Browser
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 分类在区间里面和左边.右边三种情况. 看看l的左边有没有标签.r的右边有没有标签. 就能做完了. [代码] #include < ...
- 【2017 Multi-University Training Contest - Team 2】 Is Derek lying?
[Link]: [Description] 两个人都做了完全一样的n道选择题,每道题都只有'A','B','C' 三个选项,,每道题答对的话得1分,答错不得分也不扣分,告诉你两个人全部n道题各自选的是 ...