QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#377388#6395. Equation DiscoveringKeyIDWA 43ms149672kbC++172.2kb2024-04-05 13:01:432024-04-05 13:01:44

Judging History

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

  • [2024-04-05 13:01:44]
  • 评测
  • 测评结果:WA
  • 用时:43ms
  • 内存:149672kb
  • [2024-04-05 13:01:43]
  • 提交

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.015) {
              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: 4304kb

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

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

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: 43ms
memory: 149672kb

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