P1008 trifecta - Los Valley
Title Description
The 1,2, ..., 9 9 number into three groups, each consisting of three three-digit number, and configured so that the three three-digit 1: 2: 3 ratio, satisfy the conditions of the test to obtain all three three digits.
The problem with whole next_permutation permutation function () 1 ~ 9 full array, spell three numbers, the output matching answers.
answer:
#include<iostream> #include<algorithm> using namespace std; int main(){ int num[9] = {1,2,3,4,5,6,7,8,9}; do{ int a = num[0]*100+num[1]*10+num[2]; int b = num[3]*100+num[4]*10+num[5]; int c = num[6]*100+num[7]*10+num[8]; if(a*2==b&&a*3==c) { cout<<a<<" "<<b<<" "<<c<<endl; } }while(next_permutation(num,num+9)); return 0; }