QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#105602 | #6395. Equation Discovering | woyouxiangbaile# | TL | 11ms | 13268kb | C++14 | 4.4kb | 2023-05-14 15:16:05 | 2023-05-14 15:16:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, d, u) for(int i = d; i <= u; ++i)
#define dep(i, u, d) for(int i = u; i >= d; --i)
#define cep(n) while(n--)
#define gep(i, a) for(int i = firs[a]; i; i = neig[i])
int ured() {
int re = 0;
char ch;
do {
ch = getchar();
} while('9' < ch || ch < '0');
do {
re = re * 10 + (ch ^ '0');
} while('0' <= (ch = getchar()) && ch <= '9');
return re;
}
void uwit(int da) {
int ch[21], cn = 0;
do {
ch[++cn] = da - da / 10 * 10;
} while(da /= 10);
do {
putchar('0' ^ ch[cn]);
} while(--cn);
}
const int _maxn = 20, _maxs = 5000011;
const double _epsn = 0.0001, _epss = 0.000001;
int n;
double x[_maxn], y[_maxn];
struct node {
int cp;
double da[_maxn];
} atno, queu[_maxs], tono;
node operator+(node le, node ri) {
node re;
re . cp = le . cp + ri . cp + 2;
rep(i, 0, n - 1) {
re . da[i] = le . da[i] + ri . da[i];
}
return re;
}
node operator-(node le, node ri) {
node re;
re . cp = le . cp + ri . cp + 2;
rep(i, 0, n - 1) {
re . da[i] = le . da[i] - ri . da[i];
}
return re;
}
node operator*(node le, node ri) {
node re;
re . cp = le . cp + ri . cp + 2;
rep(i, 0, n - 1) {
re . da[i] = le . da[i] * ri . da[i];
}
return re;
}
node operator/(node le, node ri) {
node re;
re . cp = le . cp + ri . cp + 2;
rep(i, 0, n - 1) {
re . da[i] = le . da[i] / ri . da[i];
}
return re;
}
node qsin(node da) {
node re;
re . cp = da . cp + 1;
rep(i, 0, n - 1) {
re . da[i] = sin(da . da[i]);
}
return re;
}
node qcos(node da) {
node re;
re . cp = da . cp + 1;
rep(i, 0, n - 1) {
re . da[i] = cos(da . da[i]);
}
return re;
}
int head, tail, stat[_maxs], lson[_maxs], rson[_maxs];
bool operator<(node le, node ri) {
if(le . cp != ri . cp) {
return le . cp < ri . cp;
}
rep(i, 0, n - 1) {
if(fabs(le . da[i] - ri . da[i]) > _epss) {
return le . da[i] < ri . da[i];
}
}
return 0;
}
set<node> sets;
bool pdif;
void outp(int at) {
putchar('(');
if(stat[at] == 1) {
outp(lson[at]), putchar('+'), outp(rson[at]);
} else if(stat[at] == 2) {
outp(lson[at]), putchar('-'), outp(rson[at]);
} else if(stat[at] == 3) {
outp(lson[at]), putchar('*'), outp(rson[at]);
} else if(stat[at] == 4) {
outp(lson[at]), putchar('/'), outp(rson[at]);
} else if(stat[at] == 5) {
putchar('s'), putchar('i'), putchar('n'), outp(lson[at]);
} else if(stat[at] == 6) {
putchar('c'), putchar('o'), putchar('s'), outp(lson[at]);
} else {
putchar('x');
}
putchar(')');
}
int main() {
n = ured();
rep(i, 0, n - 1) {
scanf("%lf%lf", &x[i], &y[i]), queu[1] . da[i] = x[i];
}
sets . insert(queu[++tail]);
while(head < tail) {
pdif = 1, atno = queu[++head];
rep(i, 0, n - 1) {
if(fabs(atno . da[i] - y[i]) > _epsn) {
pdif = 0;
break;
}
}
if(pdif) {
outp(head), putchar('\n');
break;
}
rep(i, 1, head) {
if(!sets . count(tono = atno + queu[i]) && tono . cp <= 9) {
sets . insert(tono), queu[++tail] = tono, stat[tail] = 1, lson[tail] = head, rson[tail] = i;
}
if(!sets . count(tono = atno - queu[i]) && tono . cp <= 9) {
sets . insert(tono), queu[++tail] = tono, stat[tail] = 2, lson[tail] = head, rson[tail] = i;
}
if(!sets . count(tono = queu[i] - atno) && tono . cp <= 9) {
sets . insert(tono), queu[++tail] = tono, stat[tail] = 2, lson[tail] = i, rson[tail] = head;
}
if(!sets . count(tono = atno * queu[i]) && tono . cp <= 9) {
sets . insert(tono), queu[++tail] = tono, stat[tail] = 3, lson[tail] = head, rson[tail] = i;
}
pdif = 1;
rep(j, 0, n - 1) {
if(fabs(atno . da[j]) < _epsn) {
pdif = 0;
break;
}
}
if(pdif && !sets . count(tono = atno / queu[i]) && tono . cp <= 9) {
sets . insert(tono), queu[++tail] = tono, stat[tail] = 4, lson[tail] = head, rson[tail] = i;
}
pdif = 1;
rep(j, 0, n - 1) {
if(fabs(queu[i] . da[j]) < _epsn) {
pdif = 0;
break;
}
}
if(pdif && !sets . count(tono = queu[i] / atno) && tono . cp <= 9) {
sets . insert(tono), queu[++tail] = tono, stat[tail] = 4, lson[tail] = i, rson[tail] = head;
}
}
if(!sets . count(tono = qsin(atno)) && tono . cp <= 9) {
sets . insert(tono), queu[++tail] = tono, stat[tail] = 5, lson[tail] = head;
}
if(!sets . count(tono = qcos(atno)) && tono . cp <= 9) {
sets . insert(tono), queu[++tail] = tono, stat[tail] = 6, lson[tail] = head;
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 10112kb
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: 0ms
memory: 10760kb
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: 3ms
memory: 10084kb
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: 0
Accepted
time: 11ms
memory: 13268kb
input:
5 25.032427 -0.100652 38.727324 1.658518 27.684334 -0.669555 64.282391 8.275303 52.640700 -0.962660
output:
((sin(x))/(cos(x)))
result:
ok great!!
Test #5:
score: -100
Time Limit Exceeded
input:
5 78.611917 -0.992212 -29.857271 1.011993 -75.513655 1.006611 68.512394 1.145128 7.961096 0.881661