QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#117543 | #6395. Equation Discovering | installb# | WA | 732ms | 3692kb | C++14 | 2.2kb | 2023-07-01 16:15:57 | 2023-07-01 16:15:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
int T;
db x[25],y[25];
int ch[2][25],val[25];
int sonc[8] = {0,2,2,2,2,1,1,0}; // / + - * / sin cos x
int tot = 0,cplx = 0;
db chk(int u,db x,int &flg){
if(val[u] == 7) return x;
db ls,rs;
ls = chk(ch[0][u],x,flg);
if(val[u] >= 1 && val[u] <= 4) rs = chk(ch[1][u],x,flg);
if(val[u] == 4 && rs < 0.01) flg = 0;
if(val[u] == 1) return ls + rs;
if(val[u] == 2) return ls - rs;
if(val[u] == 3) return ls * rs;
if(val[u] == 4) return ls / rs;
if(val[u] == 5) return sin(ls);
if(val[u] == 6) return cos(ls);
assert(0);
}
void print(int u){
cout << '(';
if(val[u] == 7) cout << 'x';
if(val[u] == 5) cout << "sin(";
if(val[u] == 6) cout << "cos(";
if(val[u] >= 1 && val[u] <= 6) print(ch[0][u]);
if(val[u] >= 5 && val[u] <= 6) cout << ')';
if(val[u] == 1) cout << "+";
if(val[u] == 2) cout << "-";
if(val[u] == 3) cout << "*";
if(val[u] == 4) cout << "/";
if(val[u] >= 1 && val[u] <= 4) print(ch[1][u]);
cout << ')';
}
void dfs(int u){
// cout << u << ' ' << tot << ' ' << cplx << endl;
// for(int i = 1;i <= tot;i ++) cout << val[i] << ',' << ch[0][i] << ',' << ch[1][i] << " \n"[i == tot];
// cout << endl;
if(u > tot){
int flg = 1;
for(int i = 1;i <= T;i ++){
if(fabs(chk(1,x[i],flg) - y[i]) / max(1.0L,fabs(y[i])) > 0.99e-3) flg = 0;
}
if(flg){
print(1);
exit(0);
}
return;
}
for(int i = 1;i <= 7;i ++){
if(sonc[i] + cplx > 9) continue;
for(int j = 0;j < sonc[i];j ++) ch[j][u] = ++ tot;
cplx += sonc[i];
val[u] = i;
dfs(u + 1);
val[u] = 0;
tot -= sonc[i];
cplx -= sonc[i];
for(int j = 0;j < sonc[i];j ++) ch[j][u] = 0;
}
}
void solve(){
cin >> T;
for(int i = 1;i <= T;i ++) cin >> x[i] >> y[i];
tot = 1; cplx = 0;
dfs(1);
cout << "NO\n";
}
int main(){
ios::sync_with_stdio(false);
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 6ms
memory: 3520kb
input:
3 1.000000 1.000000 2.000000 4.000000 3.000000 9.000000
output:
(((sin((x)))-(sin((x))))+((x)*(x)))
result:
ok great!!
Test #2:
score: 0
Accepted
time: 7ms
memory: 3688kb
input:
3 0.618000 1.517072 0.314000 3.132637 1.414000 0.494016
output:
(((x)-(x))+(((sin((x)))/(x))/(x)))
result:
ok great!!
Test #3:
score: 0
Accepted
time: 1ms
memory: 3532kb
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))+((x)+(x)))
result:
ok great!!
Test #4:
score: -100
Wrong Answer
time: 732ms
memory: 3692kb
input:
5 25.032427 -0.100652 38.727324 1.658518 27.684334 -0.669555 64.282391 8.275303 52.640700 -0.962660
output:
NO
result:
wrong answer Token parameter [name=out-expr] equals to "NO", doesn't correspond to pattern "[\+\-*/sincox\(\)]{1,1000}"