QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#242573#6395. Equation Discoveringucup-team902RE 1ms4280kbC++171.9kb2023-11-07 15:16:032023-11-07 15:16:04

Judging History

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

  • [2023-11-07 15:16:04]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:4280kb
  • [2023-11-07 15:16:03]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

#define gc c=getchar()
#define r(x) read(x)
#define db double

valarray<db> x_arr;
valarray<db> y_arr;

vector<pair<string, valarray<db>>> expr[10];

inline bool check(valarray<db> &arr){
    for(auto &x: arr) if(abs(x) < 0.01) return false;
    return true;
}

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("%lf%lf", &x_arr[i], &y_arr[i]);
    }
    expr[0].emplace_back(make_pair("x", x_arr));
    for(int i = 1; i <= 9; ++i){
        for(auto &[str, val]: expr[i - 1]){
            expr[i].emplace_back(make_pair("sin(" + str + ")", sin(val)));
            expr[i].emplace_back(make_pair("cos(" + str + ")", sin(val)));
        }
        for(int j = 0; j < i - 1; ++j){
            for(auto &[str1, val1] : expr[j]){
                for(auto &[str2, val2] : expr[i - j - 2]){
                    expr[i].emplace_back(make_pair("(" + str1 + "+" + str2 + ")", val1 + val2));
                    expr[i].emplace_back(make_pair("(" + str1 + "-" + str2 + ")", val1 - val2));
                    expr[i].emplace_back(make_pair("(" + str1 + "*" + str2 + ")", val1 * val2));
                    if(check(val2)){
                        expr[i].emplace_back(make_pair("(" + str1 + "/" + str2 + ")", val1 / val2));
                    }
                }
            }
        }
        for(auto &[str, val]: expr[i]){
            bool found = 1;
            for(int i = 0; i < n; ++i){
                if(abs(val[i] - y_arr[i]) > max(abs(y_arr[i]), 1.0) * 1e-3){
                    found = 0;
                    break;
                }
            }
            if(found){
                printf("%s\n", str.c_str());
                return 0;
            }
        }
    }
    assert(0);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4200kb

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: 1ms
memory: 4264kb

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: 1ms
memory: 4280kb

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
Runtime Error

input:

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

output:


result: