Codeforces_851

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces_851相关的知识,希望对你有一定的参考价值。

A.分三种情况。

技术分享
#include<bits/stdc++.h>
using namespace std;

int n,k,t;

int main()
{
    ios::sync_with_stdio(0);
    cin >> n >> k >> t;
    if(t <= k)  cout << t << endl;
    else if(t <= n) cout << k << endl;
    else    cout << k-(t-n) << endl;
}
View Code

B.a,b,c不共线且ab == bc则Yes。

技术分享
#include<bits/stdc++.h>
using namespace std;

long long ax,ay,bx,by,cx,cy;

int main()
{
    ios::sync_with_stdio(0);
    cin >> ax >> ay >> bx >> by >> cx >> cy;
    if((ay-by)*(bx-cx) == (by-cy)*(ax-bx) || (ay-by)*(ay-by)+(ax-bx)*(ax-bx) != (by-cy)*(by-cy)+(bx-cx)*(bx-cx))    cout << "No" << endl;
    else    cout << "Yes" << endl;
    return 0;
}
View Code

C.暴力剪枝一下。

技术分享
#include<bits/stdc++.h>
#define PI acos(-1)
using namespace std;

int n,ok[1005];
struct xx
{
    double a1,a2,a3,a4,a5;
}a[1005];

double f(int i,int j,int k)
{
    double t1 = a[k].a1-a[i].a1,t2 = a[k].a2-a[i].a2,t3 = a[k].a3-a[i].a3,t4 = a[k].a4-a[i].a4,t5 = a[k].a5-a[i].a5;
    double x1 = a[j].a1-a[i].a1,x2 = a[j].a2-a[i].a2,x3 = a[j].a3-a[i].a3,x4 = a[j].a4-a[i].a4,x5 = a[j].a5-a[i].a5;
    return acos((t1*x1+t2*x2+t3*x3+t4*x4+t5*x5)/sqrt(t1*t1+t2*t2+t3*t3+t4*t4+t5*t5)/sqrt(x1*x1+x2*x2+x3*x3+x4*x4+x5*x5));
}

int main()
{
    ios::sync_with_stdio(0);
    cin >> n;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i].a1 >> a[i].a2 >> a[i].a3 >> a[i].a4 >> a[i].a5;
        ok[i] = 1;
    }
    for(int i = 1;i <= n;i++)
    {
        if(!ok[i])   continue;
        for(int j = 1;j <= n;j++)
        {
            if(i == j)  continue;
            if(!ok[i])  break;
            for(int k = 1;k <= n;k++)
            {
                if(k == i)  continue;
                if(k == j)  continue;
                if(!ok[i])  break;
                double t1 = f(i,k,j);
                double t2 = f(k,i,j);
                double t3 = f(j,k,i);
                if(t1/PI*180 < 90-1e-6) ok[i] = 0;
                if(t2/PI*180 < 90-1e-6) ok[k] = 0;
                if(t3/PI*180 < 90-1e-6) ok[j] = 0;
            }
        }
    }
    int cnt = 0;
    for(int i = 1;i <= n;i++)
    {
        if(ok[i])  cnt++;
    }
    cout << cnt << endl;
    for(int i = 1;i <= n;i++)
    {
        if(ok[i])  cout << i << endl;
    }
    return 0;
}
View Code

D.暴力每个gcd的值,统计前缀个数和前缀和,优化一下。

技术分享
#include<bits/stdc++.h>
using namespace std;

int n,cnt[2000005] = {0},vis[2000005] = {0};
long long x,y,sum[2000005] = {0};

int main()
{
    ios::sync_with_stdio(0);
    cin >> n >> x >> y;
    for(int i = 1 ;i <= n;i++)
    {
        int x;
        cin >> x;
        cnt[x]++;
        sum[x] += x;
    }
    for(int i = 1;i <= 2000000;i++)
    {
        cnt[i] += cnt[i-1];
        sum[i] += sum[i-1];
    }
    long long ans = 1e18;
    for(int i = 2;i <= 1000000;i++)
    {
        if(vis[i])  continue;
        long long xx = 0;
        for(int j = i;j <= 1000000+i;j += i)
        {
            vis[j] = 1;
            int t = max(j-(int)(x/y),j-i+1);
            xx += ((long long)(cnt[j]-cnt[t-1])*j-(sum[j]-sum[t-1]))*y;
            xx += (cnt[t-1]-cnt[j-i])*x;
        }
        ans = min(ans,xx);
    }
    cout << ans << endl;
    return 0;
}
View Code

 

以上是关于Codeforces_851的主要内容,如果未能解决你的问题,请参考以下文章

codeforces 851D Arpa and a list of numbers

Arpa and an exam about geometry(codeforces 851B)

Codeforces 851D Arpa and a list of numbers

2015 百度之星初赛 1 2 2015ACM/ICPC亚洲区上海站 codeforces 851

LeetCode每日一题——851. 喧闹和富有

[Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)][C. Playing Piano](代码片段