2021CCPC华为云挑战赛problem-A-B

题目:

对象存储调度问题

卷业务模型分析

目录

A.对象存储调度问题

B.卷业务模型分析

总结


A.对象存储调度问题

思路:每次选最大的数填充最大的空间。

方法:使用2个优先队列。

#include <bits/stdc++.h>
#define bbn 100001
typedef  long long int  LL;
using namespace std;
LL t,n,m,x,y,dx;
int main()
{
    scanf("%lld",&t);
    while(t--)
    {
        bool judge=1;
        priority_queue<LL,vector<LL>,less<LL>> a;
        priority_queue<LL,vector<LL>,less<LL>> q;
        scanf("%lld%lld",&n,&m);
        for(int i=1; i<=n; i++)
        {
            scanf("%lld",&x);
            a.push(x);
        }
        for(int i=1; i<=m; i++)
        {
            scanf("%lld",&x);
            q.push(x);
        }
        while(!a.empty()&&judge)
        {
            x=a.top();
            a.pop();
            while(!q.empty()&&judge)
            {
                y=q.top();
                q.pop();
                dx=y-x;
                if(dx>=0)
                {
                    q.push(dx);
                    break;
                }
                else
                {
                    judge=0;
                    break;
                }
            }
        }
        if(judge)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
    }
    return 0;
}


B.卷业务模型分析

思路:比较数据契合度(数据在一元一次方程上)。

方法:比较相关系数 | r | 。

#include <bits/stdc++.h>
#define bbn 100001
using namespace std;
int t,n;
double x,y;
double gama(vector<double> A, vector<double> B, int Length)
{
    double sumA(0.0), sumB(0.0), aveA(0.0), aveB(0.0);
 
    sumA = std::accumulate(A.begin(), A.end(), 0.0);
    sumB = std::accumulate(B.begin(), B.end(), 0.0);
 
    aveA = sumA / double(Length);
    aveB = sumB / double(Length);
 
    double R1(0), R2(0), R3(0);
    for (long i = 0; i < Length; i++)
    {
        R1 += (A[i] - aveA) * (B[i] - aveB);
        R2 += pow((A[i] - aveA), 2);
        R3 += pow((B[i] - aveB), 2);
    }
    return (R1 / sqrt(R2*R3));
}
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        vector<double> a,b,c;
        for(int i=0; i<=n-1; i++)
        {
            scanf("%lf",&x);
            a.push_back(x);
        }
        for(int i=0; i<=n-1; i++)
        {
            scanf("%lf",&x);
            b.push_back(x);
        }
        for(int i=0; i<=n-1; i++)
        {
            scanf("%lf",&x);
            c.push_back(x);
        }
 
        x=abs(gama(a,c,n));
        y=abs(gama(b,c,n));
        if(x>y)
        {
            printf("1\n");
        }
        else
        {
            printf("2\n");
        }
    }
}


总结

 

菜鸟一只...勿喷...

2021.8.21


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值