QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#377379#6395. Equation DiscoveringKeyIDWA 74ms150520kbC++172.2kb2024-04-05 12:59:072024-04-05 12:59:08

Judging History

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

  • [2024-04-05 12:59:08]
  • 评测
  • 测评结果:WA
  • 用时:74ms
  • 内存:150520kb
  • [2024-04-05 12:59:07]
  • 提交

answer

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

typedef long long LL;

#define fi first
#define sc second
#define pb push_back

const int MAXN = 20;

typedef array<double, MAXN> ND;
typedef pair<double, double> pdd;

struct Equation {
  string s;
  ND res;
};

void solve() {
  int n;
  pdd eq[MAXN];
  vector<Equation> f[10];

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lf%lf", &eq[i].fi, &eq[i].sc);
  }

  f[0].pb({"x"});

  for (int i = 0; i < n; i++) {
    f[0][0].res[i] = eq[i].fi;
  }

  for (int i = 0; i <= 9; i++) {
    if (i) {
      for (const Equation& e : f[i - 1]) {
        ND t;

        for (int j = 0; j < n; j++) {
          t[j] = sin(e.res[j]);
        }

        f[i].pb({"sin(" + e.s + ')', t});

        for (int j = 0; j < n; j++) {
          t[j] = cos(e.res[j]);
        }

        f[i].pb({"cos(" + e.s +')', t});
      }
    }

    for (int j = 0; j <= i - 2; j++) {
      for (const Equation& lhs : f[j]) {
        for (const Equation& rhs : f[i - 2 - j]) {
          ND t;

          auto UpdateF = [&f, &t, &lhs, &rhs, n, i](auto op, char sym) {
            for (int k = 0; k < n; k++) {
              t[k] = op(lhs.res[k], rhs.res[k]);
            }

            f[i].pb({'(' + lhs.s + ')' + sym + '(' + rhs.s + ')', t});
          };

          UpdateF(plus<double>(), '+');
          UpdateF(minus<double>(), '-');
          UpdateF(multiplies<double>(), '*');

          bool div_flag = true;

          for (int k = 0; k < n; k++) {
            if (rhs.res[k] < 0.15) {
              div_flag = false;
              break;
            }
          }

          if (div_flag) {
            UpdateF(divides<double>(), '/');
          }
        }
      }
    }

    for (const Equation& e : f[i]) {
      bool ok = true;

      for (int j = 0; j < n; j++) {
        if (abs(e.res[j] - eq[j].sc) / max(1.0, abs(eq[j].sc)) > 1e-4) {
          ok = false;
          break;
        }
      }

      if (ok) {
        cout << e.s;

        return;
      }
    }
  }
}

int main() {
#ifdef KeyID
  freopen("read.txt","r",stdin);
#endif

  solve();

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 4504kb

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: 4408kb

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: 74ms
memory: 150520kb

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