QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#516418#6395. Equation DiscoveringhuayucaijiWA 112ms196460kbC++143.3kb2024-08-12 17:07:442024-08-12 17:07:45

Judging History

你现在查看的是最新测评结果

  • [2024-08-12 17:07:45]
  • 评测
  • 测评结果:WA
  • 用时:112ms
  • 内存:196460kb
  • [2024-08-12 17:07:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

int read() {
	char ch=getchar();
	int f=1,x=0;
	while(ch<'0'||ch>'9') {
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		x=x*10+ch-'0';
		ch=getchar();
	}
	return f*x;
}
char read_char() {
	char ch=getchar();
	while(!isalpha(ch)) {
		ch=getchar();
	}
	return ch;
}

const int MAXN=30;

int n;
long double x[MAXN],fx[MAXN];
struct equation {
	string s;
	long double y[MAXN];
	
	bool check() {
		for(int i=1;i<=n;i++) {
			if(abs(y[i]-fx[i])>1e-6) {
				return 0;
			}
		}
		return 1;
	}
	void output() {
		cout<<s<<endl;
	}
}ori;
vector<equation> g[10];

int main() {
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>x[i]>>fx[i];
		ori.y[i]=x[i];
	}
	
	ori.s="x";
	if(ori.check()) {
		ori.output();
		return 0;
	}
	g[0].push_back(ori);
	
	for(int i=1;i<=9;i++) {
		int sz=g[i-1].size();
		
		//sin(x)
		for(int j=0;j<sz;j++) {
			equation t;
			t.s="sin("+g[i-1][j].s+")";
			for(int k=1;k<=n;k++) {
				t.y[k]=sin(g[i-1][j].y[k]);
			}
			if(t.check()) {
				t.output();
				return 0;
			}
			g[i].push_back(t);
		}
		
		//cos(x)
		for(int j=0;j<sz;j++) {
			equation t;
			t.s="cos("+g[i-1][j].s+")";
			for(int k=1;k<=n;k++) {
				t.y[k]=cos(g[i-1][j].y[k]);
			}
			if(t.check()) {
				t.output();
				return 0;
			}
			g[i].push_back(t);
		}
		
		//x+x
		for(int j=0;j<=i-2;j++) {
			int k=i-2-j;
			if(k<j) break;
			
			int szj=g[j].size();
			int szk=g[k].size();
			for(int p=0;p<szj;p++) {
				for(int q=0;q<szk;q++) {
					equation t;
					t.s=g[j][p].s+"+"+g[k][q].s;
					for(int l=1;l<=n;l++) {
						t.y[l]=g[j][p].y[l]+g[k][q].y[l];
					}
					
					if(t.check()) {
						t.output();
						return 0;
					}
					g[i].push_back(t);
				}
			}
		}
		
		//x*x
		for(int j=0;j<=i-2;j++) {
			int k=i-2-j;
			if(k<j) break;
			
			int szj=g[j].size();
			int szk=g[k].size();
			for(int p=0;p<szj;p++) {
				for(int q=0;q<szk;q++) {
					equation t;
					t.s="("+g[j][p].s+")*("+g[k][q].s+")";
					for(int l=1;l<=n;l++) {
						t.y[l]=g[j][p].y[l]*g[k][q].y[l];
					}
					
					if(t.check()) {
						t.output();
						return 0;
					}
					g[i].push_back(t);
				}
			}
		}
		
		//x-x
		for(int j=0;j<=i-2;j++) {
			int k=i-2-j;
			
			int szj=g[j].size();
			int szk=g[k].size();
			for(int p=0;p<szj;p++) {
				for(int q=0;q<szk;q++) {
					equation t;
					t.s=g[j][p].s+"-"+g[k][q].s;
					for(int l=1;l<=n;l++) {
						t.y[l]=g[j][p].y[l]-g[k][q].y[l];
					}
					
					if(t.check()) {
						t.output();
						return 0;
					}
					g[i].push_back(t);
				}
			}
		}
		
		
		//x/x
		for(int j=0;j<=i-2;j++) {
			int k=i-2-j;
			
			int szj=g[j].size();
			int szk=g[k].size();
			for(int p=0;p<szj;p++) {
				for(int q=0;q<szk;q++) {
					bool flag=1;
					equation t;
					t.s="("+g[j][p].s+")/("+g[k][q].s+")";
					for(int l=1;l<=n;l++) {
						if(g[k][q].y[l]<1e-6) {
							flag=0;
							break;
						}
						t.y[l]=g[j][p].y[l]/g[k][q].y[l];
					}
					
					if(!flag) {
						continue;
					}
					if(t.check()) {
						t.output();
						return 0;
					}
					g[i].push_back(t);
				}
			}
		}
	}

	//fclose(stdin);
	//fclose(stdout);
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 4016kb

input:

3
1.000000 1.000000
2.000000 4.000000
3.000000 9.000000

output:

(x)*(x)

result:

ok great!!

Test #2:

score: 0
Accepted
time: 0ms
memory: 4316kb

input:

3
0.618000 1.517072
0.314000 3.132637
1.414000 0.494016

output:

(sin(x))/((x)*(x))

result:

ok great!!

Test #3:

score: 0
Accepted
time: 0ms
memory: 4116kb

input:

5
77.685777 233.057331
-66.445083 -199.335249
79.966717 239.900151
84.982130 254.946390
-31.528900 -94.586700

output:

x+x+x

result:

ok great!!

Test #4:

score: -100
Wrong Answer
time: 112ms
memory: 196460kb

input:

5
25.032427 -0.100652
38.727324 1.658518
27.684334 -0.669555
64.282391 8.275303
52.640700 -0.962660

output:


result:

wrong output format Unexpected end of file - token expected