QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#242645 | #6395. Equation Discovering | ucup-team902 | WA | 0ms | 4064kb | C++17 | 1.6kb | 2023-11-07 16:00:27 | 2023-11-07 16:00:28 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define db float
#define mp make_pair
#define ep emplace_back
valarray<db> x_arr;
valarray<db> y_arr;
vector<pair<string, valarray<db>>> expr[10];
inline bool check(valarray<db> &arr){
for(int i = 0; i < x_arr.size(); ++i) if(abs(arr[i] - y_arr[i]) > max(abs(y_arr[i]), 1.0f) * 1e-3) return 0;
return 1;
}
int main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int n; scanf("%d", &n);
x_arr.resize(n);
y_arr.resize(n);
for(int i = 0; i < n; ++i){
db x, y; scanf("%f%f", &x_arr[i], &y_arr[i]);
}
expr[0].ep(mp("x", x_arr));
for(int i = 1; i <= 9; ++i){
for(auto &[f, y]: expr[i - 1]){
expr[i].ep(mp("sin(" + f + ")", sin(y)));
expr[i].ep(mp("cos(" + f + ")", cos(y)));
}
for(int j = 0; j < i - 1; ++j){
for(auto &[f1, y1] : expr[j]){
for(auto &[f2, y2] : expr[i - j - 2]){
expr[i].ep(mp("(" + f1 + "+" + f2 + ")", y1 + y2));
expr[i].ep(mp("(" + f1 + "-" + f2 + ")", y1 - y2));
expr[i].ep(mp("(" + f1 + "*" + f2 + ")", y1 * y2));
if(abs(y2).min() >= 0.01){
expr[i].ep(mp("(" + f1 + "/" + f2 + ")", y1 / y2));
}
}
}
}
for(auto &[f, y]: expr[i]){
if(check(y_arr)){
printf("%s\n", f.c_str());
return 0;
}
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 4064kb
input:
3 1.000000 1.000000 2.000000 4.000000 3.000000 9.000000
output:
sin(x)
result:
wrong answer fail to discover