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

 

转载于:https://www.cnblogs.com/zhurb/p/7481891.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值