您的位置:首页 > 其它

Tsinsen A1109 三角形

2016-04-03 16:22 169 查看
http://oj.tsinsen.com/A1109

分析:呃..不知道有没有好的数学搞法,反正直接暴力破解也就那么算了~

代码:

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

int p, a[9], OK, res[9];

int main() {
scanf("%d", &p);
for (int i = 0; i < 9; ++i)
a[i] = i + 1;
do {
if (a[0] > a[5] || a[0] > a[8] || a[5] > a[8]) continue;
if (a[1] > a[3] || a[6] > a[7] || a[2] > a[4]) continue;
if (a[0] + a[1] + a[3] + a[5] != p) continue;
if (a[5] + a[6] + a[7] + a[8] != p) continue;
if (a[8] + a[4] + a[2] + a[0] != p) continue;
OK += 1;
if (OK <= 1) for (int i = 0; i < 9; ++i)
res[i] = a[i];
} while (next_permutation(a, a + 9));
if (OK <= 0) puts("NO");
else printf("%d\n%d\n%d %d\n%d %d\n%d %d %d %d\n",
OK, res[0], res[1], res[2], res[3], res[4], res[5], res[6], res[7], res[8]);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: