• Codeforces Round #432 (Div. 2)


    A. Arpa and a research in Mexican wave

    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 stands.
    • At time k + 1, the (k + 1)-th spectator stands and the first spectator sits.
    • At time k + 2, the (k + 2)-th spectator stands and the second spectator sits.
    • ...
    • At time n, the n-th spectator stands and the (n - k)-th spectator sits.
    • At time n + 1, the (n + 1 - k)-th spectator sits.
    • ...
    • At time n + k, the n-th spectator sits.

    Arpa wants to know how many spectators are standing at time t.

    Input

    The first line contains three integers nkt (1 ≤ n ≤ 109, 1 ≤ k ≤ n1 ≤ t < n + k).

    Output

    Print single integer: how many spectators are standing at time t.

    Examples
    input
    10 5 3
    output
    3
    input
    10 5 7
    output
    5
    input
    10 5 12
    output
    3
    Note

    In the following a sitting spectator is represented as -, a standing spectator is represented as ^.

    • At t = 0  ----------  number of standing spectators = 0.
    • At t = 1  ^---------  number of standing spectators = 1.
    • At t = 2  ^^--------  number of standing spectators = 2.
    • At t = 3  ^^^-------  number of standing spectators = 3.
    • At t = 4  ^^^^------  number of standing spectators = 4.
    • At t = 5  ^^^^^-----  number of standing spectators = 5.
    • At t = 6  -^^^^^----  number of standing spectators = 5.
    • At t = 7  --^^^^^---  number of standing spectators = 5.
    • At t = 8  ---^^^^^--  number of standing spectators = 5.
    • At t = 9  ----^^^^^-  number of standing spectators = 5.
    • At t = 10 -----^^^^^  number of standing spectators = 5.
    • At t = 11 ------^^^^  number of standing spectators = 4.
    • At t = 12 -------^^^  number of standing spectators = 3.
    • At t = 13 --------^^  number of standing spectators = 2.
    • At t = 14 ---------^  number of standing spectators = 1.
    • At t = 15 ----------  number of standing spectators = 0.

    题意:给定一种波浪,求每一时刻有多少个站起来了;

    #include <bits/stdc++.h>
    
    using namespace std;
    
    int main()
    {
        int n,k,t;
        scanf("%d%d%d",&n,&k,&t);
    
        if(t<=k)
            printf("%d
    ",t);
        else if(t<=n)
            printf("%d
    ",k);
        else if(t<=n+k)
            printf("%d
    ",n-t+k);
        else puts("0");
        t++;
    
    
        return 0;
    }
    B. Arpa and an exam about geometry

    Arpa is taking a geometry exam. Here is the last problem of the exam.

    You are given three points a, b, c.

    Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.

    Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.

    Input

    The only line contains six integers ax, ay, bx, by, cx, cy (|ax|, |ay|, |bx|, |by|, |cx|, |cy| ≤ 109). It's guaranteed that the points are distinct.

    Output

    Print "Yes" if the problem has a solution, "No" otherwise.

    You can print each letter in any case (upper or lower).

    Examples
    input
    0 1 1 1 1 0
    output
    Yes
    input
    1 1 0 0 1000 1000
    output
    No
    Note

    In the first sample test, rotate the page around (0.5, 0.5) by .

    In the second sample test, you can't find any solution.

    题意:给三个点的坐标a,b,c,看是否经过绕顶点旋转,a 旋转到 b,b到c;

    分析:刚开始考虑三个点的外接圆,然后比较圆形角,麻烦了,而且不删除计算几何。

    其实,就是 b 到 a,c的距离相等,还要不能在同一条直线上。

    距离很好判断,判断三个点是否在同一条直线上,斜率的判定,不能有除以0,于是我转为求余弦,但是结果是long long double 精度都不够,

    最好是分类讨论:

    #include <bits/stdc++.h>
    
    using namespace std;
    
    int main()
    {
        long long int ax,ay,bx,by,cx,cy;
        cin>>ax>>ay>>bx>>by>>cx>>cy;
    
        long long int l1 = (by-ay)*(by-ay) + (bx-ax)*(bx-ax);
        long long int l2 = (cy-by)*(cy-by) + (cx-bx)*(cx-bx);
    
        int mark = 0;
    
        if( (ax==bx&&ax==cx) || (ay==by&&ay==cy) )
            mark = 1;
        else {
            double k1 = (by-ay)*1.0/(bx-ax);
            double k2 = (cy-by)*1.0/(cx-bx);
    
            if(k1==k2)
                mark = 1;
        }
    
        if(mark==1)
            puts("No");
        else if (l1!=l2)
            puts("No");
        else puts("Yes");
    
        return 0;
    }
    D. Arpa and a list of numbers

    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 cost x.
    • Choose a number and increase it by 1 with cost y.

    Arpa can apply these operations to as many numbers as he wishes, and he is allowed to apply the second operation arbitrarily many times on the same number.

    Help Arpa to find the minimum possible cost to make the list good.

    Input

    First line contains three integers nx and y (1 ≤ n ≤ 5·105, 1 ≤ x, y ≤ 109) — the number of elements in the list and the integers x and y.

    Second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the elements of the list.

    Output

    Print a single integer: the minimum possible cost to make the list good.

    Examples
    input
    4 23 17
    1 17 17 16
    output
    40
    input
    10 6 2
    100 49 71 73 66 96 8 60 41 63
    output
    10
    Note

    In example, number 1 must be deleted (with cost 23) and number 16 must increased by 1 (with cost 17).

    gcd (greatest common divisor) of a set of numbers is the maximum integer that divides all integers in the set. Read more about gcd here.

    题意:给定一个序列,和 x,y,将这个序列删除任意一个花费 x,将任意一个元素+1花费y;求一些操作以后整个序列的gcd!=1;

    分析:

    最近数论题做的很少了,没有啥想法,大牛们下了一个定理,什么调和级数一搞,推出这个gcd一定是一个素数。

    然后枚举这个10^6里面的素数,我就直接暴力了,稍微剪了一下。

    大佬们是求两个区间和,在一定区间内删掉,一定区间内补上,这样的贪心就O(1)内求出花费。

    #include <bits/stdc++.h>
    
    using namespace std;
    
    typedef long long ll;
    
    const int maxn = 500005;
    const int maxnum = 1e6 + 5;
    
    int a[maxn];
    int sum[maxnum];
    int vis[maxnum];
    
    int main()
    {
        int n,x,y;
        scanf("%d%d%d",&n,&x,&y);
    
        for(int i = 0; i < n; i++) {
            scanf("%d",&a[i]);
            sum[a[i]] ++;
        }
    
        ll cnt = 0x3f3f3f3f3f3f3f3fll;
    
        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((ll)1*x,(ll)1*y*(i-t));
                        }
                    }
                    cnt = min(cnt,tans);
                }
            }
        }
    
        printf("%lld
    ",cnt);
    
    
        return 0;
    }
  • 相关阅读:
    list for循环中删除元素
    XMLFeedSpider例子
    myeclipse一直卡在loading workbench解决方法
    代码
    在Github上面搭建Hexo博客(一):部署到Github
    RegEX正则表达式截取字符串
    将后台值传单前台js接收
    C# List<T>泛型用法
    基于jQuery——TreeGrid
    在线编程学习网站
  • 原文地址:https://www.cnblogs.com/TreeDream/p/7517538.html
Copyright © 2020-2023  润新知