QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#242727#6395. Equation Discoveringucup-team902Compile Error//C++171.3kb2023-11-07 16:40:202023-11-07 16:40:20

Judging History

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

  • [2023-11-07 16:40:20]
  • 评测
  • [2023-11-07 16:40:20]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

#define db double
#define va valarray
#define mp make_pair
#define ep emplace_back

va<db> x0;
va<db> y0;

inline void ins(vector<pair<string, va<db>>> &arr, const string &f, const va<db> &y){
    if(abs(y - y0).max() <= 1e-3){
        printf("%s\n", f.c_str());
        exit(0);
    }
    arr.ep(mp(f, y));
}

vector<pair<string, va<db>>> e[10];

int main(){
    int n; cin >> n;
    x0.resize(n);
    y0.resize(n);
    for(int i = 0; i < n; ++i){
       cin >> x0[i] >> y0[i];
    }
    ins(e[0], "x", x0);
    for(int i = 1; i <= 9; ++i){
        for(auto &[f, y]: e[i - 1]){
            ins(e[i], "sin(" + f + ")", sin(y));
            ins(e[i], "cos(" + f + ")", cos(y));
        }
        for(int j = 0; j < i - 1; ++j){
            for(auto &[f1, y1] : e[j]){
                for(auto &[f2, y2] : e[i - j - 2]){
                    if(j >= i - j - 2){
                        ins(e[i], "(" + f1 + "+" + f2 + ")", y1 + y2);
                        ins(e[i], "(" + f1 + "*" + f2 + ")", y1 * y2);
                    }
                    ins(e[i], "(" + f1 + "-" + f2 + ")", y1 - y2);
                    if(abs(y2).min() >= 0.01){
                        ins(e[i], "(" + f1 + "/" + f2 + ")", y1 / y2);
                    }
                }
            }
        }
    }
}

Details

answer.code:11:8: error: ‘std::valarray<double> y0’ redeclared as different kind of entity
   11 | va<db> y0;
      |        ^~
In file included from /usr/include/features.h:461,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/c++config.h:586,
                 from /usr/include/c++/11/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:33,
                 from answer.code:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:220:1: note: previous declaration ‘double y0(double)’
  220 | __MATHCALL (y0,, (_Mdouble_));
      | ^~~~~~~~~~
answer.code: In function ‘void ins(std::vector<std::pair<std::__cxx11::basic_string<char>, std::valarray<double> > >&, const string&, const std::valarray<double>&)’:
answer.code:14:14: error: no match for ‘operator-’ (operand types are ‘const std::valarray<double>’ and ‘double(double) noexcept’)
   14 |     if(abs(y - y0).max() <= 1e-3){
      |            ~ ^ ~~
      |            |   |
      |            |   double(double) noexcept
      |            const std::valarray<double>
In file included from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:95,
                 from answer.code:1:
/usr/include/c++/11/valarray:1091:5: note: candidate: ‘typename std::valarray<_Tp>::_UnaryOp<std::__negate>::_Rt std::valarray<_Tp>::operator-() const [with _Tp = double; typename std::valarray<_Tp>::_UnaryOp<std::__negate>::_Rt = std::valarray<double>::_UnaryOp<std::__negate>::_Rt]’
 1091 |     _DEFINE_VALARRAY_UNARY_OPERATOR(-, __negate)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/11/valarray:1091:5: note:   candidate expects 0 arguments, 1 provided
In file included from /usr/include/c++/11/bits/stl_algobase.h:67,
                 from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from answer.code:1:
/usr/include/c++/11/bits/stl_iterator.h:577:5: note: candidate: ‘template<class _IteratorL, class _IteratorR> constexpr decltype ((__y.base() - __x.base())) std::operator-(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)’
  577 |     operator-(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/11/bits/stl_iterator.h:577:5: note:   template argument deduction/substitution failed:
answer.code:14:16: note:   ‘const std::valarray<double>’ is not derived from ‘const std::reverse_iterator<_Iterator>’
   14 |     if(abs(y - y0).max() <= 1e-3){
      |                ^~
In file included from /usr/include/c++/11/bits/stl_algobase.h:67,
                 from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from answer.code:1:
/usr/include/c++/11/bits/stl_iterator.h:1693:5: note: candidate: ‘template<class _IteratorL, class _IteratorR> constexpr decltype ((__x.base() - __y.base())) std::operator-(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)’
 1693 |     operator-(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/11/bits/stl_iterator.h:1693:5: note:   template argument deduction/substitution failed:
answer.code:14:16: note:   ‘const std::valarray<double>’ is not derived from ‘const std::move_iterator<_IteratorL>’
   14 |     if(abs(y - y0).max() <= 1e-3){
      |                ^~
In file included from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:1:
/usr/include/c++/11/complex:362:5: note: candidate: ‘template<class _Tp> std::complex<_Tp> std::operator-(const std::complex<_Tp>&, const std::complex<_Tp>&)’
  362 |     operator-(const complex<_Tp>& __x, const complex<_Tp>& __y)
      |     ^~~~~~~~
/usr/include/c++/11/complex:362:5: note:   template argument deduction/substitution failed:
answer.code:14:16: note:   ‘const std::valarray<double>’ is not derived from ‘const std::complex<_Tp>’
   14 |     if(abs(y - y0).max() <= 1e-3){
      |                ^~
In file included from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:1:
/usr/include/c++/11/complex:371:5: note: candidate: ‘template<class _Tp> std::complex<_Tp> std::operator-(const std::complex<_Tp>&, const _Tp&)’
  371 |     operator-(const complex<_Tp>& __x, const _Tp& __y)
      |     ^~~~~~~~
/usr/include/c++/11/complex:371:5: note:   template argument deduction/substitution failed:
answer.code:14:16: note:   ‘const std::valarray<double>’ is not derived from ‘const std::complex<_Tp>’
   14 |     if(abs(y - y0).max() <= 1e-3){
      |                ^~
In file included from /usr/include/c++/11/ccomplex:39,
              ...