QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#104934 | #6395. Equation Discovering | ckiseki# | Compile Error | / | / | C++20 | 4.0kb | 2023-05-12 15:53:36 | 2023-05-12 15:53:38 |
Judging History
你现在查看的是最新测评结果
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2023-05-12 15:53:38]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-05-12 15:53:36]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
template <typename ...T>
void debug_(const char *s, T ...a) {
cerr << "\e[1;32m(" << s << ") = (";
int cnt = sizeof...(T);
(..., (cerr << a << (--cnt ? ", " : ")\e[0m\n")));
}
template <typename I>
void orange_(const char *s, I L, I R) {
cerr << "\e[1;32m[ " << s << " ] = [ ";
for (int f = 0; L != R; ++L)
cerr << (f++ ? ", " : "") << *L;
cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif
namespace {
using llf = long double;
constexpr int maxn = 20;
pair<llf, llf> f[maxn];
llf readf() {
llf x; cin >> x;
return x;
int x, y;
scanf("%d.%d", &x, &y);
if (x < 0)
return x - y / 1e6l;
return x + y / 1e6l;
}
const string op_name[] = {
"+",
"-",
"*",
"/",
"sin",
"cos"
};
struct node {
node *lc, *rc;
int op;
node() : lc(nullptr), rc(nullptr), op(-1) {}
};
llf err(llf a, llf b) {
return abs(a - b) / max<llf>(1, abs(b));
}
optional<llf> eval(node *r, llf x) {
if (r == nullptr)
return x;
if (r->op < 4) {
auto lhs = eval(r->lc, x);
auto rhs = eval(r->rc, x);
if (not lhs or not rhs)
return nullopt;
if (r->op == 0)
return *lhs + *rhs;
if (r->op == 1)
return *lhs - *rhs;
if (r->op == 2)
return *lhs * *rhs;
if (r->op == 3) {
if (abs(*rhs) < 0.01)
return nullopt;
return *lhs / *rhs;
}
__builtin_unreachable();
} else {
auto v = eval(r->lc, x);
if (not v)
return nullopt;
if (r->op == 4)
return sin(*v);
if (r->op == 5)
return cos(*v);
__builtin_unreachable();
}
}
void dump(node *r) {
putchar('(');
if (r == nullptr) {
putchar('x');
} else if (r->op < 2) {
dump(r->lc);
printf(op_name[r->op].c_str());
dump(r->rc);
} else if (r->op < 4) {
dump(r->lc);
printf(op_name[r->op].c_str());
dump(r->rc);
} else {
printf(op_name[r->op].c_str());
putchar('(');
dump(r->lc);
putchar(')');
}
putchar(')');
}
void check(node *r, int n) {
for (int i = 0; i < n; ++i) {
if (auto v = eval(r, f[i].first); not v or err(*v, f[i].second) > 1e-3) {
return;
}
}
dump(r);
putchar('\n');
exit(0);
}
void solve(vector<node *> &v, size_t p, int b, int n) {
if (p == v.size()) {
check(v[0], n);
return;
}
node *cur = v[p];
node lhs{}, rhs{};
if (b >= 2) {
for (int i = 0; i < 4; ++i) {
cur->op = i;
cur->lc = nullptr, cur->rc = nullptr;
solve(v, p + 1, b - 2, n);
cur->lc = nullptr, cur->rc = &rhs;
v.push_back(cur->rc);
solve(v, p + 1, b - 2, n);
v.pop_back();
cur->lc = &lhs, cur->rc = nullptr;
v.push_back(cur->lc);
solve(v, p + 1, b - 2, n);
v.pop_back();
cur->lc = &lhs, cur->rc = &rhs;
v.push_back(cur->lc), v.push_back(cur->rc);
solve(v, p + 1, b - 2, n);
v.pop_back(), v.pop_back();
}
}
if (b >= 1) {
for (int i = 4; i < 6; ++i) {
cur->op = i;
cur->lc = nullptr;
solve(v, p + 1, b - 1, n);
cur->lc = &lhs;
v.push_back(cur->lc);
solve(v, p + 1, b - 1, n);
v.pop_back();
}
}
}
} // namespace
int main() {
int n; scanf("%d", &n);
for (int i = 0; i < n; ++i) {
f[i].first = readf();
f[i].second = readf();
}
node r{};
vector<node *> v = {&r};
solve(v, 0, 9, n);
return 0;
}
詳細信息
answer.code: In function ‘{anonymous}::llf {anonymous}::readf()’: answer.code:38:9: error: conflicting declaration ‘int x’ 38 | int x, y; | ^ answer.code:36:9: note: previous declaration as ‘{anonymous}::llf x’ 36 | llf x; cin >> x; | ^ answer.code:39:13: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘{anonymous}::llf*’ {aka ‘long double*’} [-Wformat=] 39 | scanf("%d.%d", &x, &y); | ~^ ~~ | | | | int* {anonymous}::llf* {aka long double*} | %Le answer.code: In function ‘void {anonymous}::dump({anonymous}::node*)’: answer.code:102:15: warning: format not a string literal and no format arguments [-Wformat-security] 102 | printf(op_name[r->op].c_str()); | ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ answer.code:106:15: warning: format not a string literal and no format arguments [-Wformat-security] 106 | printf(op_name[r->op].c_str()); | ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ answer.code:109:15: warning: format not a string literal and no format arguments [-Wformat-security] 109 | printf(op_name[r->op].c_str()); | ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ answer.code: In function ‘int main()’: answer.code:176:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 176 | int n; scanf("%d", &n); | ~~~~~^~~~~~~~~~ answer.code: In function ‘{anonymous}::llf {anonymous}::readf()’: answer.code:39:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 39 | scanf("%d.%d", &x, &y); | ~~~~~^~~~~~~~~~~~~~~~~