Codeforces Round #432 (Div. 2) D. Arpa and a list of numbers(暴力)

枚举质数,判断是否超过临界值。临界值就是将不是因子中不含这个素数的数的个数乘以x和y的较小值,是否小于当前最小值。

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>

#define Max 1000001
#define MAXN 500005
#define MAXNUM 1000005
#define MOD 100000000
#define rin freopen("in.txt","r",stdin)
#define rout freopen("1.out","w",stdout)
#define Del(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const LL LINF = 0x3f3f3f3f3f3f3f3fLL;

int a[MAXN];
int sum[MAXNUM];
int vis[MAXNUM];
int n, x, y;
int main() {
    //rin;
    scanf("%d%d%d", &n, &x, &y);
    Del(sum, 0);
    Del(vis, 0);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        sum[a[i]]++;
    }
    LL cnt = LINF;

    for (int i = 2; i <= 1000000; i++) {
        if (!vis[i]) {
            LL ans = sum[i];
            for (int j = 2 * i; j <= 1000000; j += i)
                vis[j] = 1, ans += sum[j];
            if ((n - ans) * min(x, y) < cnt) {
                LL tans = 0;
                for (int j = 0; j < n; j++) {
                    if (a[j] % i) {
                        LL t = a[j] % i;
                        tans += min(1ll * x, 1ll * y * (i - t));
                    }
                }
                cnt = min(cnt, tans);
            }
        }
    }
    printf("%lld",cnt);
    return 0;
}
时间: 2024-10-04 23:20:20

Codeforces Round #432 (Div. 2) D. Arpa and a list of numbers(暴力)的相关文章

Codeforces Round #286 (Div. 2)B. Mr. Kitayuta&#39;s Colorful Graph(dfs,暴力)

数据规模小,所以就暴力枚举每一种颜色的边就行了. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<cmath> #include<map> #include<set> #include<vector> #include<algorithm>

D. Arpa and a list of numbers Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)

http://codeforces.com/contest/851/problem/D 分区间操作 1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <time.h> 6 #include <string> 7 #include <set> 8 #include <map> 9

Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) A

Arpa is researching the Mexican wave. There are n spectators in the stadium, labeled from 1 to n. They start the Mexican wave at time 0. At time 1, the first spectator stands. At time 2, the second spectator stands. ... At time k, the k-th spectator

Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) D

Arpa has found a list containing n numbers. He calls a list bad if and only if it is not empty and gcd (see notes section for more information) of numbers in the list is 1. Arpa can perform two types of operations: Choose a number and delete it with

【枚举】Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) Div2C题

题目大意: 平面上有N个点(N<=1000),定义一个点为好,当且仅当,由这个点为三角形的顶点,组成的所有三角形,两边的夹角都为钝角,称为好点,求好点的数目. 题目分析: 首先考虑朴素的枚举,枚举三元组<i,j,k>,以i为顶点,j , k 为两边 ,查看是否i为顶点的所有三角形,都以i所在顶点为钝角. 考虑优化: 三角形内角和是180 如果<i, j, k> 是以i为顶点的钝角/直角三角形,则 j, k 是坏点,不需要枚举. 如果<i, j, k> 是锐角,i为

Codeforces Round #324 (Div. 2) D. Dima and Lisa (哥德巴赫猜想 + 暴力)

D. Dima and Lisa Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes. More formally, you are given

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我