poj 2362 Square
来源:互联网 发布:java简单请假系统 编辑:程序博客网 时间:2024/06/14 21:47
题目来源:http://poj.org/problem?id=2362
跟poj1011, nyoj 293大体思路一样!
但是这个题要有自身的剪枝!:http://blog.csdn.net/hearthougan/article/details/22986249
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 25;int Len_Of_Sticks[MAXN];bool visit[MAXN];int num;bool DFS(int CurLen, int kcount, int pos, int EdgeLen){ if(kcount == 3)//有三条边满足,没那么就可以组成正方形,新加判别条件 return true; for(int i = pos; i < num; ++i) { if(!visit[i]) { if(Len_Of_Sticks[i] + CurLen == EdgeLen) { visit[i] = true; if(DFS(0, kcount+1, 0, EdgeLen)) return true; visit[i] = false; return false; } else if(Len_Of_Sticks[i] + CurLen < EdgeLen) { visit[i] = true; if(DFS(Len_Of_Sticks[i] + CurLen, kcount, i+1, EdgeLen)) return true; visit[i] = false; bool flag = (CurLen == 0 ? true : false); if(flag) return false; while(Len_Of_Sticks[i] == Len_Of_Sticks[i+1]) ++i; } } } return false;}int cmp(int a, int b){ return a > b;}int main(){ int T, sum, Edge; int i; scanf("%d", &T); while(T--) { scanf("%d", &num); sum = 0; for(i = 0; i < num; ++i) { scanf("%d", &Len_Of_Sticks[i]); sum += Len_Of_Sticks[i]; } if(num < 4 || sum % 4 != 0)//边数小于4 || 长度之和不能被4整除自然不可以 { printf("no\n"); continue ; } memset(visit, false, sizeof(visit)); sort(Len_Of_Sticks, Len_Of_Sticks+num, cmp); Edge = sum/4; if(Edge < Len_Of_Sticks[0])//最长的小棒不能大于边!!! { printf("no\n"); continue ; } if(DFS(0, 0, 0, Edge)) printf("yes\n"); else printf("no\n"); } return 0;}
0 0
- poj 2362 Square
- poj 2362 Square
- poj 2362Square(DFS)
- poj 2362 Square
- POJ 2362 Square dfs
- poj 2362 Square
- POJ-2362-Square
- POJ 2362 Square
- poj 2362 Square
- poj 2362 Square
- POJ 2362 Square
- POJ 2362 Square DFS
- POJ 2362 Square
- poj 2362 Square
- poj 2362 Square
- POJ - 2362 Square
- poj 2362 Square
- poj 2362:Square
- linux 安装、编译boost库
- 如何把熬夜伤害降到最低
- [Hadoop源码解读](一)MapReduce篇之InputFormat (转)
- linux下android开发:
- HDU 1198 Farm Irrigation(并查集)
- poj 2362 Square
- Android自定义Button按钮显示样式
- [Hadoop源码解读](二)MapReduce篇之Mapper类 (转)
- HDU 1241 Oil Deposits (DFS)
- C#总结
- RGB24转YUV420P
- [Hadoop源码解读](三)MapReduce篇之Job类 (转)
- 怎样更改SQL Server 2005的身份验证模式
- 9.5 VS2010中调试c++程序的方法