跳到正文

题解

题解 P1008 【三连击】

CancerGary约 1 分钟
原文
文章信息与版本

文章信息

收录
2026年7月14日
更新
2026年7月22日
篇幅
约 1 分钟
获赞
3
题目
P1008

版本

  1. v1当前

虽然题目很水,不过试了下STL的全排列感觉桑心病狂= =

[c++]

C++
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int a[]={1,2,3,4,5,6,7,8,9};
    int i,j;
    for (i=1;i<=362880;i++){
        //for (j=0;j<5;j++) cout << a[j] << " ";
        if (((a[0]*100+a[1]*10+a[2])*3==(a[6]*100+a[7]*10+a[8]))&&
        ((a[0]*100+a[1]*10+a[2])*2==(a[3]*100+a[4]*10+a[5]))) {
            for (j=0;j<3;j++) cout << a[j*3] << a[j*3+1]<< a[j*3+2]<<" ";
            cout <<endl;
        }
        next_permutation(a,a+9);//STL全排列函数
    }
    return 0;
}
[/c++]
原文
存档评论8 条抓取于