题目:
目录
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