Codeforces 432 Div. 2-D-Arpa and a list of numbers(枚举倍数求GCD)
来源:互联网 发布:天池 大数据 编辑:程序博客网 时间:2024/05/20 07:33
题意:给你n个数,然后用两种操作使得这n个数的gcd不为1,每种操作有不同的成本,问你最小成本是多少
操作1:将这个数删除(花费为x) 操作2:将这个数加一(可以一直加,每加一次花费为y)
题解:昨晚总想着枚举因数,然后暴力求共约数,复杂度n*sqrt(m) (m为数组中最大的数)
但是其中有很多问题,比如说有n-1个很大的质数,然后只有一个不是质数的话这方法是行不通吧,好吧
其实本来复杂度也是过不了关的,呢怎么办呢。。枚举gcd,然后暴力倍数。。。昨晚怎么不会搞23333
#include<set> #include<map> #include<stack> #include<queue> #include<vector> #include<string> #include<math.h> #include<stdio.h> #include<iostream> #include<string.h> #include<stdlib.h> #include<algorithm> #include<functional> using namespace std;typedef __int64 ll;#define inf 1000000000 #define mod 1000000007 #define maxn 2000005 #define PI 3.1415926 #define lowbit(x) (x&-x) #define eps 1e-9 ll a[maxn], b[maxn];int main(void){ll ans;ll i, j, k, p, n, x, y, xx;scanf("%I64d%I64d%I64d", &n, &x, &y);for (i = 1;i <= n;i++){scanf("%I64d", &xx);a[xx]++;b[xx] += xx;}for (i = 1;i <= 2000000;i++)a[i] += a[i - 1], b[i] += b[i - 1];p = x / y;ans = 100000000000000000;for (i = 2;i <= 1000000;i++){ll tmp = 0;for (j = i;j <= 1000000 + i && tmp <= ans;j += i){k = max(j - i + 1, j - p);tmp += ((a[j] - a[k - 1])*j - (b[j] - b[k - 1]))*y;tmp += (a[k - 1] - a[j - i])*x;}ans = min(ans, tmp);}printf("%I64d\n", ans);return 0;}
阅读全文
1 0
- Codeforces 432 Div. 2-D-Arpa and a list of numbers(枚举倍数求GCD)
- Codeforces Round #432 (Div. 2) D 850B Arpa and a list of numbers(gcd 枚举)
- Codeforces Codeforces Round #432 (Div. 2 D ) Arpa and a list of numbers 爆搜+剪枝
- Codeforces Codeforces Round #432 (Div. 2 D ) Arpa and a list of numbers
- Codeforces Round #432 (Div. 2) D. Arpa and a list of numbers E. Arpa and a game with Mojtaba
- 解题报告:Codeforces Round #432 (Div. 2) D. Arpa and a list of numbers 暴力
- Codeforces 851D Arpa and a list of numbers Round #432 (Div. 2
- Codeforces 851D Arpa and a list of numbers (枚举+分段)
- Codeforces 851D. Arpa and a list of numbers
- Codeforces Round #432 (Div. 1): B. Arpa and a list of numbers
- Codeforces Round #432 (Div. 1) B. Arpa and a list of numbers
- Codeforces Round #432 -思维&素数筛魔改-D-Arpa and a list of numbers
- Codeforces 851 D. Arpa and a list of numbers(技巧)
- Codeforces 851 D Arpa and a list of numbers(前缀和)
- Codeforces Round #432 B. Arpa and a list of numbers
- codeforces 851 D. Arpa and a list of numbers(前缀和+bruteforce)
- Codeforces 851D Arpa and a list of numbers【思维+前缀和】
- codeforces 850B Arpa and a list of numbers
- python中json格式数据输出实现方式(无unicode编码输出形式)
- Mybatis逆向工程生成不带注释的文件
- 二维凸包模板
- springMVC对静态资源放行配置
- 网络编程
- Codeforces 432 Div. 2-D-Arpa and a list of numbers(枚举倍数求GCD)
- 在Andorid中使用FFmpeg实现YUV编码为MP4
- python操作docx文档
- AJAX第五步:使用ajax解决页面首页显示后台数据的问题
- struts2添加自己的校验器
- QT开发(四十)——GraphicsView编程
- 动态查看最近300行的代码
- 机器学习-- 逻辑回归
- Hdu 5784 How Many Triangles(极角排序+尺取法)