tvick11 @ 2024-12-06 22:46:45
代码如下:
#include<bits/stdc++.h>//万能头文件启动
#include<math.h>
#include<algorithm>
using namespace std;
struct s
{
long long fen;
long long line;
}c[1000003];
bool com(s a,s b)
{
return a.line<b.line;
}
int n,m;
int er(int x)//二分查找
{
int star=0,end=n+1;
int mid=(star+end)/2;
while(star+1<end)
{
if(c[mid].line==x)return 0;
else if(c[mid].line>x)
{
end=mid;
mid=(star+end)/2;
}
else
{
star=mid;
mid=(star+end)/2;
}
}
return min(abs(x-c[mid].line),abs(c[mid+1].line-x));
}
int main()
{
c[0].line=-1000;
cin>>n>>m;
long long ans=0;
for(int i=1;i<=n;i++)
{
cin>>c[i].line;
}
sort(c+1,c+n+1,com);
for(int i=0;i<m;i++)
{
cin>>c[i].fen;
ans+=er(c[i].fen);
}
printf("%lld",ans);
return 0;
}
by EasonMo2014 @ 2024-12-07 21:36:24
#include<bits/stdc++.h>
using namespace std;
float a,b,c,d;
float f(float x){
float y=a*x*x*x+b*x*x+c*x+d;
return y;
}
int main(){
cin>>a>>b>>c>>d;
// cout<<fff(-2.00);
for(float i=-100;i<=100;i+=0.01){
if(f(i)*f(i+0.01)<0){
cout<<fixed<<setprecision(2)<<i+0.005<<" ";
// if(abs(f(i))<abs(f(i+0.01)))cout/*<<fixed<<setprecision(2)*/<<i<< " ";
}
}
return 0;
}