Codeforces Round#431(Div.2)

A. Arpa and a research in Mexican wave

A题里面也算简单的了……

#include<bits/stdc++.h>
using namespace std;
int n,k,t;
int main(){
    cin>>n>>k>>t;
    if(t<=k) cout<<t<<endl;
    else if(t<=n) cout<<k;
    else cout<<k+n-t;
    return 0;
} 

B. Arpa and an exam about geometry

三点不共线 && |AB| == |BC|

#include<bits/stdc++.h>
using namespace std;
struct Point{
    long long x,y;
}a,b,c;
bool inLine(Point a,Point b,Point c){
    if((c.y-a.y)*(b.x-a.x) == (b.y-a.y)*(c.x-a.x)) return true;
    return false;
}
int main(){
    cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y;
    if(inLine(a,b,c)) return 0*printf("No
");
    long long fbc = pow(b.x-a.x,2)+pow(b.y-a.y,2);
    long long fab = pow(b.x-c.x,2)+pow(b.y-c.y,2);
    if(fbc != fab) return 0*printf("No
");
    printf("Yes
");
    return 0;
} 

C. Five Dimensional Points

分析三维情况,在答案不为0的情况下使点的个数尽可能多,即均取90°,显然最多7个点,二维情况下是5个点(十字情况),那么可以推得五维状况下不超过11个点,n<=11时O(n^3)枚举

#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[105][5];
int n,Ans,b[105];
bool check(int i)
{
    for (int j=1;j<=n;j++)
        for (int k=j+1;k<=n;k++)
            if (i!=j&&i!=k)
            {
                ll tmp=0;
                for (int l=1;l<=5;l++) 
                    tmp+=(a[j][l]-a[i][l])*(a[k][l]-a[i][l]);
                if (tmp>0) return 0;
            }
    return 1;
}
int main()
{
    scanf("%d",&n);
    if (n>11)
    {
        puts("0");
    }
    else
    {
        for (int i=1;i<=n;i++)
        for (int j=1;j<=5;j++)
            scanf("%I64d",&a[i][j]);
        for (int i=1;i<=n;i++)
        {
            Ans+=b[i]=check(i);
        }
        printf("%d
",Ans);
        for (int i=1;i<=n;i++)
        if (b[i])
        {
            printf("%d
",i);
        }
    }
} 

D. Arpa and a list of numbers

对代码中变量说明:

p 当前数字(向上加)与目标数字的倍数差p及以上时,删除比一直加一直到目标数字更优

c/s 当前index前所有数字个数 / 数字之和

i 为目标数字,j为目标数字的倍数

对每个长度为 i 的区间,取其最优解即可

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int c[1<<21];
ll  s[1<<21];
ll x, y; int p;
int main()
{

    scanf("%d%I64d%I64d",&n,&x,&y);
    p = (x + y - 1)/y;
    for(int i = 0; i <n ;++i){
        int w;
        scanf("%d",&w);
        c[w]++;
        s[w] += w;
    }

    for(int i = 1; i< (1<<21); ++i)
    {
        c[i] += c[i-1];
        s[i] += s[i-1];
    }

    ll ans = n * x;
    for(int i = 2; i <= 1000000; i++)
    {
        ll t = 0;
        for(int j = i; j <= 1000000 + i && t < ans; j += i)
        {
            int k = max( j - i, j - p);
            ll h = (c[j] - c[k])*(ll)j - (s[j] - s[k]);
            t += h * y;
            t += (c[k] - c[j-i])*x;
        }
        ans = min(ans, t);
    }
    printf("%I64d
", ans);

    return 0;
}

E. Arpa and a game with Mojtaba

http://www.cnblogs.com/Invisible-full-moon/p/7491447.html

原文地址:https://www.cnblogs.com/Invisible-full-moon/p/7477036.html