Talk is cheap. Show me the code. —— Linus Torvalds
Hits: 运用C++的next_permutation()
函数解题
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <set>
using namespace std;
const int MAX = 40000;
set<vector<int>> s;
int c[MAX], p[MAX];
int main()
{
// freopen("i.txt", "r", stdin);
// freopen("o.txt", "w", stdout);vector<int> v;v.push_back(0); v.push_back(50);for(int i = 1; i <= 20; i++)for(int j = 1; j <= 3; j++)v.push_back(i * j);sort(v.begin(), v.end());int limit = v.size();for(int i = 0; i < limit; i++)for(int j = 0; j < limit; j++)for(int k = 0; k < limit; k++){
vector<int> v2 = {
v[i], v[j], v[k]};int sum = v[i] + v[j] + v[k];if(s.count(v2) == 0){
c[sum]++;int t = 0;do{
t++;s.insert(v2);} while (next_permutation(v2.begin(), v2.end()));p[sum] += t;}}}}int num;while(scanf("%d", &num) && num > 0){
if(c[num] == 0)printf("THE SCORE OF %d CANNOT BE MADE WITH THREE DARTS.\n", num);else{
printf("NUMBER OF COMBINATIONS THAT SCORES %d IS %d.\n", num, c[num]);printf("NUMBER OF PERMUTATIONS THAT SCORES %d IS %d.\n", num, p[num]);}for(int i = 0; i < 70; i++) putchar('*');putchar('\n');}puts("END OF OUTPUT");return 0;
}