35pts迷惑求助
查看原帖
35pts迷惑求助
497333
I_Flipped楼主2022/7/9 16:55

蒟蒻求助

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<map>
//#define int long long
using namespace std;
typedef long long ll;
const int N=1e2+5,M=1e5+5;
const double eps=1e-6;

int read(){
    char c=getchar();int f=1,x=0;
    while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
    while(isdigit(c)){x=x*10+c-48;c=getchar();}
    return x*f;
}

int t,n,m,ans;
double x[N],y[N],asa[N],asb[N],resx[N],resy[N];
bool flag;

bool pd(double a,double b){return fabs(a-b)<eps;}

void dfs(int c,int u,int v){
	if(u+v>ans){return ;}
	if(c>n){ans=u+v;return ;}
	flag=false;
	for(int i=1;i<=u;++i){
		if(pd(asa[i]*x[c]*x[c]+asb[i]*x[c],y[c])){
			flag=true;
			dfs(c+1,u,v);
			break;
		}
	}
	if(!flag){
		for(int i=1;i<=v;++i){
			if(pd(x[c],resx[i]))continue;
			double a=(y[c]*resx[i]-resy[i]*x[c])/(resx[i]*x[c]*x[c]-resx[i]*resx[i]*x[c]),b=(y[c]-a*x[c]*x[c])/x[c];
			if(a<0){
				asa[u+1]=a,asb[u+1]=b;
				double q=resx[i],p=resy[i];
				for(int j=1;j<v;++j)resx[j]=resx[j+1],resy[j]=resy[j+1];
				dfs(c+1,u+1,v-1);
				for(int j=v;j>i;--j)resx[j]=resx[j-1],resy[j]=resy[j-1];
				resx[i]=q,resy[i]=p;
			}
		}
		resx[v+1]=x[c],resy[v+1]=y[c];
		dfs(c+1,u,v+1);
	}
}

signed main(){
	t=read();
	while(t--){
		n=read(),m=read();
		for(int i=1;i<=n;++i)scanf("%lf%lf",&x[i],&y[i]);
		ans=100;
		dfs(1,0,0);
		printf("%d\n",ans);
	}
	return 0;
}

又及:无法通过样例3

谢谢谢谢谢谢

2022/7/9 16:55
加载中...