QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#591186#2510. Make Numbersmrkiencf#AC ✓1ms3912kbC++203.1kb2024-09-26 14:40:542024-09-26 14:40:55

Judging History

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

  • [2024-09-26 14:40:55]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3912kb
  • [2024-09-26 14:40:54]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int O = 2e5 + 5;

int n, a[4], b[4];
vector <int> res, id;

void Do(vector <int> c){
    if (c.size() == 1){
        //res.push_back(c[0]);
    }

    if (c.size() == 2){
        res.push_back(c[0] * c[1]);
        res.push_back(c[0] - c[1]);
        res.push_back(c[0] + c[1]);
    }

    if (c.size() == 3){
        res.push_back(c[0] * c[1] - c[2]);
        res.push_back(c[0] * c[1] + c[2]);
        res.push_back(c[0] * c[1] * c[2]);
        res.push_back(c[0] + c[1] - c[2]);
        res.push_back(c[0] + c[1] + c[2]);
        res.push_back(c[0] + c[1] * c[2]);
        res.push_back(c[0] - c[1] - c[2]);
        res.push_back(c[0] - c[1] + c[2]);
        res.push_back(c[0] - c[1] * c[2]);
    }

    if (c.size() == 4){
        res.push_back(c[0] * c[1] - c[2] + c[3]);
        res.push_back(c[0] * c[1] - c[2] - c[3]);
        res.push_back(c[0] * c[1] - c[2] * c[3]);
        res.push_back(c[0] * c[1] + c[2] + c[3]);
        res.push_back(c[0] * c[1] + c[2] - c[3]);
        res.push_back(c[0] * c[1] + c[2] * c[3]);
        res.push_back(c[0] * c[1] * c[2] + c[3]);
        res.push_back(c[0] * c[1] * c[2] - c[3]);
        res.push_back(c[0] * c[1] * c[2] * c[3]);

        res.push_back(c[0] - c[1] - c[2] + c[3]);
        res.push_back(c[0] - c[1] - c[2] - c[3]);
        res.push_back(c[0] - c[1] - c[2] * c[3]);
        res.push_back(c[0] - c[1] + c[2] + c[3]);
        res.push_back(c[0] - c[1] + c[2] - c[3]);
        res.push_back(c[0] - c[1] + c[2] * c[3]);
        res.push_back(c[0] - c[1] * c[2] + c[3]);
        res.push_back(c[0] - c[1] * c[2] - c[3]);
        res.push_back(c[0] - c[1] * c[2] * c[3]);

        res.push_back(c[0] + c[1] - c[2] + c[3]);
        res.push_back(c[0] + c[1] - c[2] - c[3]);
        res.push_back(c[0] + c[1] - c[2] * c[3]);
        res.push_back(c[0] + c[1] + c[2] + c[3]);
        res.push_back(c[0] + c[1] + c[2] - c[3]);
        res.push_back(c[0] + c[1] + c[2] * c[3]);
        res.push_back(c[0] + c[1] * c[2] + c[3]);
        res.push_back(c[0] + c[1] * c[2] - c[3]);
        res.push_back(c[0] + c[1] * c[2] * c[3]);
    }

}

void cal(int pos, int x, int lim){
    if (pos == 4){
        //b[lim] = x;
        if (x) return;
        vector <int> c;
        for (int i = 0; i < lim; ++ i){
            c.push_back(b[i]);
            //cout << b[i] << " ";
        }
        Do(c);
        //cout << endl;
        return;
    }

    b[lim] = x * 10 + a[id[pos]];
    cal(pos + 1, 0, lim + 1);
    cal(pos + 1, x * 10 + a[id[pos]], lim);
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    for (int i = 0; i < 4; ++ i){
        id.push_back(i);
        cin >> a[i];
    }

    do {
        cal(0, 0, 0);
    } while(next_permutation(id.begin(), id.end()));

    sort(res.begin(), res.end());
    int m = unique(res.begin(), res.end()) - res.begin();
    res.resize(m);

    sort(res.rbegin(), res.rend());
    while (res.size() && res.back() < 0) res.pop_back();

    cout << res.size() << endl;
    //for (int i : res) cout << i << " ";
}
/**
 * 6
**/

詳細信息

Test #1:

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

input:

1 1 1 1

output:

15

result:

ok single line: '15'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

1 1 1 1

output:

15

result:

ok single line: '15'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3872kb

input:

1 1 2 1

output:

32

result:

ok single line: '32'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3684kb

input:

1 2 4 8

output:

178

result:

ok single line: '178'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

1 3 3 8

output:

107

result:

ok single line: '107'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3668kb

input:

1 1 2 1

output:

32

result:

ok single line: '32'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3912kb

input:

2 2 4 4

output:

58

result:

ok single line: '58'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3660kb

input:

2 3 4 5

output:

183

result:

ok single line: '183'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3872kb

input:

2 3 5 7

output:

191

result:

ok single line: '191'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

2 4 6 8

output:

172

result:

ok single line: '172'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

2 5 5 5

output:

54

result:

ok single line: '54'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3908kb

input:

2 8 6 4

output:

172

result:

ok single line: '172'

Test #13:

score: 0
Accepted
time: 0ms
memory: 3872kb

input:

3 3 3 3

output:

22

result:

ok single line: '22'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3836kb

input:

5 3 2 7

output:

191

result:

ok single line: '191'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

5 7 8 9

output:

217

result:

ok single line: '217'

Test #16:

score: 0
Accepted
time: 0ms
memory: 3876kb

input:

9 9 9 9

output:

20

result:

ok single line: '20'