70pts,WA on #2 #9 #10,求 hack
查看原帖
70pts,WA on #2 #9 #10,求 hack
690315
array2022楼主2024/8/4 13:32

die 码如下,自测第二个样例会 RE。

#include<bits/stdc++.h>
using namespace std;
int t,m,a,b,c,delta;
bool sq(int x) {
	int y=sqrt(x);
	return y*y==x;
}
void outq(int x,int y) {
	if (y<0) x=-x, y=-y;
	if (x==0) cout<<0;
	else if (x%y==0) cout<<x/y;
	else cout<<x/__gcd(abs(x),y)<<"/"<<y/__gcd(abs(x),y);
}
void outr(int x,int y,int r) {
	if (y<0) x=-x, y=-y;
	if (x==y) cout<<"sqrt("<<r<<")\n";
	else if (x%y==0) cout<<x/y<<"*sqrt("<<r<<")\n";
	else if (y%x==0) cout<<"sqrt("<<r<<")/"<<y/x<<"\n";
	else cout<<x/__gcd(abs(x),y)<<"*sqrt("<<r<<")"<<"/"<<y/__gcd(abs(x),y)<<"\n";
}
int main() {
	ios::sync_with_stdio(0);
	cin>>t>>m;
	while (t--) {
		cin>>a>>b>>c;
		delta=b*b-4*a*c;
		if (delta<0) {
			cout<<"NO\n";
			continue;
		}
		if (sq(delta)) {
			int x=-b+a/abs(a)*sqrt(delta),y=2*a;
			outq(x,y);
			cout<<"\n";
		} else {
			int q1x=-b,q2x=1,y=2*abs(a);
			if (q1x!=0) {
				outq(q1x,y);
				cout<<"+";
			}
			for (int i=sqrt(delta); i>=1; i--) {
				if (delta%(i*i)==0) {
					delta/=i*i;
					q2x*=i;
					break;
				}
			}
			outr(q2x,y,delta);
		}
	}
	return 0;
}
2024/8/4 13:32
加载中...