2018牛客多校5

A gpa

简单的01分数规划,用二分来搜索答案

#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define eps 1e-8
int n,k;
int s[100100];
int c[100100];
bool check(double x)
{
    double res[100100];
    for(int i=0;i<n;i++)
        res[i]=c[i]-x*s[i];
    sort(res,res+n);
    double ans=0;
    for(int i=k;i<n;i++) ans+=res[i];
    return ans>=0;
}
int main()
{
    while(~scanf("%d%d",&n,&k))
    {
        for(int i=0;i<n;i++)
            scanf("%d",&s[i]);
        for(int i=0;i<n;i++)
            scanf("%d",&c[i]),c[i]*=s[i];
        double l=0,r=1000;
        while(r-l>eps)
        {
            double m=(l+r)/2;
            if(check(m)) l=m;
            else r=m;
        }
        printf("%.6lf\n",r);
    }
    return 0;
}

 

G max

给一对c 和n 求2个数a b 小于等于n 并且gcd(a,b)=c 求a*b的最大值。

如果c=n那么答案就是n*n,如果c>n那么就输出-1

那么c<n的话,我们设a=c*A b=c*B ,如果c为a b的gcd的话,那么A和B就是互质的。

然后只要找最大的A和B即可。

#include<bits/stdc++.h>
using namespace std;
#define LL long long int
LL c,n;
bool prime(LL x)
{
    for(int i=2;i<=sqrt(x);i++)
        if(x%i==0) return 0;
    return 1;
}
LL gcd(LL a,LL b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}
int main()
{
    while(~scanf("%lld%lld",&c,&n))
    {
        if(c>n)
        {
            printf("-1\n");
            return 0;
        }
        else if(c==n)
        {
            printf("lld\n",n*n);
            return 0;
        }
        LL x=n/c;
        if(x-1)
            printf("%lld\n",x*(x-1)*c*c);
        else
            printf("%lld\n",c*c);
    }
    return 0;
}

 

J plan

贪心。。。。

#include<bits/stdc++.h>
using namespace std;
#define LL long long int
LL n,a,b;
int main()
{
    while(~scanf("%lld%lld%lld",&n,&a,&b))
    {
        double aa=a*1.0/2;
        double bb=b*1.0/3;
        LL res=0;
        if(aa<bb)
        {
            res=n/2*a;
            if(n%2)
                res+=min(a,b-a);
        }
        else
        {
            res=n/3*b;
            if(n%3==2) res+=a;
            else if(n%3==1) res+=min(a,2*a-b);
        }
        printf("%lld\n",res);
    }
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值