QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#105623 | #6395. Equation Discovering | woyouxiangbaile# | WA | 283ms | 89144kb | C++14 | 4.5kb | 2023-05-14 15:50:51 | 2023-05-14 15:50:52 |
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 long double _epsn = 0.0000001, _epss = 0.000000001;
int n;
long double x[_maxn], y[_maxn];
struct node {
int cp;
long 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;
vector<int> dats[10];
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;
}
dats[atno . cp] . push_back(head);
rep(i, 0, 7 - atno . cp) {
for(int j : dats[i]) {
if(!sets . count(tono = atno + queu[j])) {
sets . insert(tono), queu[++tail] = tono, stat[tail] = 1, lson[tail] = head, rson[tail] = j;
}
if(!sets . count(tono = atno - queu[j])) {
sets . insert(tono), queu[++tail] = tono, stat[tail] = 2, lson[tail] = head, rson[tail] = j;
}
if(!sets . count(tono = queu[j] - atno)) {
sets . insert(tono), queu[++tail] = tono, stat[tail] = 2, lson[tail] = j, rson[tail] = head;
}
if(!sets . count(tono = atno * queu[j])) {
sets . insert(tono), queu[++tail] = tono, stat[tail] = 3, lson[tail] = head, rson[tail] = j;
}
pdif = 1;
rep(j, 0, n - 1) {
if(fabs(queu[j] . da[j]) < _epsn) {
pdif = 0;
break;
}
}
if(pdif && !sets . count(tono = atno / queu[j])) {
sets . insert(tono), queu[++tail] = tono, stat[tail] = 4, lson[tail] = head, rson[tail] = j;
}
pdif = 1;
rep(j, 0, n - 1) {
if(fabs(atno . da[j]) < _epsn) {
pdif = 0;
break;
}
}
if(pdif && !sets . count(tono = queu[j] / atno)) {
sets . insert(tono), queu[++tail] = tono, stat[tail] = 4, lson[tail] = j, rson[tail] = head;
}
}
}
if(atno . cp <= 8 && !sets . count(tono = qsin(atno))) {
sets . insert(tono), queu[++tail] = tono, stat[tail] = 5, lson[tail] = head;
}
if(atno . cp <= 8 && !sets . count(tono = qcos(atno))) {
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: 3ms
memory: 9664kb
input:
3 1.000000 1.000000 2.000000 4.000000 3.000000 9.000000
output:
((x)*(x))
result:
ok great!!
Test #2:
score: -100
Wrong Answer
time: 283ms
memory: 89144kb
input:
3 0.618000 1.517072 0.314000 3.132637 1.414000 0.494016
output:
result:
wrong output format Unexpected end of file - token expected