Tsinsen A1109 三角形
2016-04-03 16:22
211 查看
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; }
相关文章推荐
- Microsoft Azure中TrafficManager (流量管理器)的路由方式
- PHP magic_quotes_gpc的详细使用方法
- 自学鸟哥linux服务-vsftpd
- 与时俱进的Java——《写给大忙人看的Java核心技术》
- HDU1379 DNA Sorting
- Hibernate的工作流程及使用的好处
- 【snaptype nexus】搭建maven私服仓库
- HDU 3033 I love sneakers!(分组背包/至少选一个)
- ACM-水题 Beauty of Array
- Okttp3.0简单的二次回调封装
- STL(1) - Lambda表达式
- html5学习系列之cd标签
- web进修之—Hibernate 懒加载(6)
- 汇编学习1
- liunx 用户,群组和权限
- 服务器架构--------iis与Apache共存搭建(都可以使用域名访问,而不带后面的:80,90等)
- from __future__ import absolute_import的作用
- Android中的Semaphore
- hdu1007 Quoit Design【平面最近点对+分治】
- 设计模式 - 动态代理