QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#504805#9136. Exponent Calculatorucup-team2307#AC ✓1ms3816kbC++202.3kb2024-08-04 16:10:532024-08-04 16:10:54

Judging History

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

  • [2024-08-04 16:10:54]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3816kb
  • [2024-08-04 16:10:53]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define int ll
#define fi first
#define se second
#define pb push_back
//typedef long double ld;
//#define double  ld

const int N = 16;
vector<double> a(N, 0.0);
vector<string> ans;

void mul(int x, int y, int z)
{
    stringstream ss;
    ss<<fixed<<setprecision(20);
    ss<<"$"<<z<<" = $"<<x<<" * $"<<y;
    ans.pb(ss.str());
    a[z] = a[x] * a[y];
}
void mulby(int x, double y, int z)
{
    stringstream ss;
    ss<<fixed<<setprecision(20);
    ss<<"$"<<z<<" = $"<<x<<" * "<<y;
    ans.pb(ss.str());
    a[z] = a[x] * y;
}
void add(int x, int y, int z)
{
    stringstream ss;
    ss<<fixed<<setprecision(20);
    ss<<"$"<<z<<" = $"<<x<<" + $"<<y;
    ans.pb(ss.str());
    a[z] = a[x] + a[y];
}
void eq(int x, double y)
{
    stringstream ss;
    ss<<fixed<<setprecision(20);
    ss<<"$"<<x<<" = "<<y;
    ans.pb(ss.str());
    a[x] = y;
}

signed main()
{
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);
    cout<<fixed<<setprecision(20);
    string s;
    cin>>s;

    double x = 20;
    a[1] = x;

    int L = 10;
    mulby(1, 1.0/(1<<L), 1);

    eq(0, 1);
    mul(1, 1, 2);
    add(0, 1, 0);
    mulby(2, 1.0/2, 3);
    add(0, 3, 0);

//    for (int i=0; i<=3; i++)
//        cout<<a[i]<<"\n";
//    cout<<"\n";

    mul(2, 1, 2);
    mulby(2, 1.0/6, 3);
    add(0, 3, 0);

//    for (int i=0; i<=3; i++)
//        cout<<a[i]<<"\n";
//    cout<<"\n";

    mul(2, 1, 2);
    mulby(2, 1.0/24, 3);
    add(0, 3, 0);

//    for (int i=0; i<=3; i++)
//        cout<<a[i]<<"\n";
//    cout<<"\n";

    mul(2, 1, 2);
    mulby(2, 1.0/120, 3);
    add(0, 3, 0);

//    for (int i=0; i<=3; i++)
//        cout<<a[i]<<"\n";
//    cout<<"\n";

//    mul(2, 1, 2);
//    mulby(2, 1.0/720, 3);
//    add(0, 3, 0);
//
//    mul(2, 1, 2);
//    mulby(2, 1.0/720/7, 3);
//    add(0, 3, 0);

    for (int i=0; i<L; i++)
        mul(0, 0, 0);

//    for (int i=0; i<=3; i++)
//        cout<<a[i]<<"\n";
//
//    double y = exp(x);
//    cout<<abs(y - a[0])/y<<"\n";
//    cout<<abs(y - a[0])/y*1e9<<"\n";
//    cout<<ans.size()<<"\n";

    cout<<ans.size()<<"\n";
    for (string s : ans)
        cout<<s<<"\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3816kb

input:

input

output:

25
$1 = $1 * 0.00097656250000000000
$0 = 1.00000000000000000000
$2 = $1 * $1
$0 = $0 + $1
$3 = $2 * 0.50000000000000000000
$0 = $0 + $3
$2 = $2 * $1
$3 = $2 * 0.16666666666666665741
$0 = $0 + $3
$2 = $2 * $1
$3 = $2 * 0.04166666666666666435
$0 = $0 + $3
$2 = $2 * $1
$3 = $2 * 0.00833333333333333322
...

result:

ok max relative diff is 8.04772e-11. Checker runtime is 200 ms

Extra Test:

score: 0
Extra Test Passed