QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#249366#6395. Equation Discoveringreal_sigma_teamWA 148ms44624kbC++202.6kb2023-11-12 04:35:522023-11-12 04:35:53

Judging History

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

  • [2023-11-12 04:35:53]
  • 评测
  • 测评结果:WA
  • 用时:148ms
  • 内存:44624kb
  • [2023-11-12 04:35:52]
  • 提交

answer

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

#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()

using ll = long long;
using ld = long double;

string ops[] = {"+", "*", "/", "-"};
string un[] = {"sin", "cos"};
const int N = 10;
vector<string>s[N];
const ld inf = 1e18;
const ld eps = 1e-6;

bool equal(ld x, ld y){
	return fabs(x - y) < eps;
}

bool ok;

ld Cos(ld x){
	return cos(x);
}

ld Sin(ld x){
	return sin(x);
}

ld Div(ld x, ld y){
	if(y <= 0.01){
		ok = false;
		return inf;
	}
	return x / y;
}

ld Plu(ld x, ld y){
	return x + y;
}

ld Min(ld x, ld y){
	return x - y;
}

ld Mul(ld x, ld y){
	return x * y;
}

function<ld(ld)> Un[] = {Sin, Cos};
function<ld(ld, ld)> Ops[] = {Plu, Mul, Div, Min};
vector<ld> rem[N];
vector<vector<int>>Go[N];
void gen(int diff){
	vector<vector<int>>go;
	int Mid = sz(Go[diff - 1]);
	for(int s_ = 0; s_ < Mid; s_++)
		for(int u = 0; u < 2; u++)
			go.push_back({diff - 1, s_, -1, u});
	if(diff >= 2){
		for(int l = 0; l <= diff - 2; l++){
			int r = diff - 2 - l;
			if(r > l)
				continue;
			int L = sz(Go[l]);
			int R = sz(Go[r]);
			for(int l_ = 0; l_ < L; l_++)
				for(int r_ = 0; r_ < R; r_++){
					for(int u = 0; u < 4; u++){
						go.push_back({l, l_, r_, u});
					}
					for(int u = 2; u < 4; u++){
						go.push_back({r, r_, l_, u});
					}
				}
		}
	}
	Go[diff] = go;
	return;
}

ld x[20], y[20];

ld getvl(int diff, int ind, ld curX){
	if(diff == 0)
		return curX;
	vector<int> g = Go[diff][ind]; 

	int l = g[0];
	if(l == diff - 1)
		return Un[g[3]](getvl(l, g[1], curX));
	int r = diff - 2 - l;
	return Ops[g[3]](getvl(l, g[1], curX), getvl(r, g[2], curX));
}

string genStr(int diff, int ind){
	if(diff == 0)
		return "x";
	vector<int> g = Go[diff][ind]; 
	int l = g[0];
	if(l == diff - 1)
		return un[g[3]] + "(" + genStr(l, g[1]) + ")";
	int r = diff - 2 - l;
	return "(" + genStr(l, g[1]) + ")" + ops[g[3]] + "(" + genStr(r, g[2]) + ")";
}


void solve(){
	int n;
	cin >> n;
	for(int i = 0 ; i < n; i++){
		cin >> x[i] >> y[i];
	}
	Go[0] = vector<vector<int>>(1, vector<int>());
	for(int i = 1; i < N; i++)
		gen(i);
	for(int Sz = 0; Sz < N; Sz++){
		for(int seq = 0; seq < Go[Sz].size(); seq++){
			bool eq = true;
			for(int i = 0; i < n; i++){
				ok = true;
				ld res = getvl(Sz, seq, x[i]);
				if(!ok || !equal(res, y[i])){
					eq = false;
					break;
				}
			}
			if(eq){
				cout << genStr(Sz, seq);
				return;
			}
		}
	}
}

int main() {
	cin.tie(nullptr) -> sync_with_stdio(false);
	solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 15ms
memory: 43500kb

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: 19ms
memory: 43532kb

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: 28ms
memory: 44624kb

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: 148ms
memory: 42944kb

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