zoukankan      html  css  js  c++  java
  • 洛谷 题解 CF299A 【Ksusha and Array】

    本蒟蒻又双叒叕被爆踩辣!

    这就是道大水题

    首先,题目意思:

    给你n个数,要你找这些数字中找到一个能够被这些所有数字整除的数,若有多个,可任意输出其中一个,其实答案只有一个,因为在大于等于自己的数中能被自己整除的数只有它自己。

    一句话题意(虽然好像本来就是一句话

    要你找到一个数(a[x]),使: (gcd(a_1,a_2,a_3…a_n)) == (a[x])

    是不是只要推出了这一步就没有任何问题了,是吧。

    接下来,来证明一下(伪证

    窝们一样例为例

    10
    2 4 14 6 10 14 122 234 232 988
    

    上面这组数据的 (gcd(a_1,a_2,a_3…a_n)) 是不是为2.是不是(gcd(a_1,a_2,a_3…a_n)) (== a[1]) 成立。

    5
    122 244 366 2 488
    

    还是一样的,这样是不是很好理解,你要找的数肯定是当前这些数中最小的,而且要保证gcd(a_1,a_2,a_3…a_n)$ (== a[x])成立。

    代码:

    #include<bits/stdc++.h>
    
    using namespace std;
    
    const int dx[5] = {0, 1, -1, 0, 0};
    const int dy[5] = {0, 0, 0, 1, -1};
    
    //#define XRZ
    #define int long long
    #define maxn 100010
    #define maxm
    #define ll long long
    #define mian main
    #define inf 0x3f3f3f3f
    #define ls (x << 1)
    #define rs (x << 1 | 1)
    #define mid (l + r >> 1)
    #define debug(x) printf("now here is %d
    ", x);
    #define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout);
    #define Rep(x, a, b) for(int x = a; x <= b; ++ x)
    #define Dep(x, a, b) for(int x = a; x >= b; -- x)
    #define Next(x, u) for(int i = head[u]; i ; i = e[i].nxt)
    
    int n, a[maxn], b[maxn], c[maxn], ans;
    
    bool cmp(int x, int y) {return x > y;}//因为要用小的序号对于大的权值,所以从大到小排序。
    
    signed mian(){
    // file(a);
    scanf("%lld", &n);//读入
    Rep(i, 1, n){
    scanf("%lld%lld", &a[i], &b[i]);//输入每个角色的属性,好像a[],b[]并没有什么鸟用
    c[i] = a[i] - b[i];//这里是窝们求的(a[i] - b[i]),窝们只要维护它即可。
    ans += (n * b[i]) - a[i];//先加上定值。
    }
    sort(c + 1, c + n + 1, cmp);//排序。。。
    Rep(i, 1, n) ans += c[i] * i;//小的序号对于大的权值
    printf("%lld", ans);//输出
    return 0;
    }
    

    ps:请看懂再抄

  • 相关阅读:
    rancher2.x添加node的坑。
    k8s相关端口表-以及周边工具
    基于Helm和Operator的K8S应用管理的分享
    iptables -F 与 -X 区别
    ansible批量免秘登录
    keepalived工作原理和配置说明
    k8s使用nfs动态存储(已测试成功)
    ansible-playbook快速入门填坑
    Service Account和其secrets 作用和场景,看了不亏。。
    kubectl管理多个k8s集群
  • 原文地址:https://www.cnblogs.com/Flash-plus/p/12028197.html
Copyright © 2011-2022 走看看