hdu 4277 USACO ORZ (暴力+set容器判重)
USACO ORZ
Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2291 Accepted Submission(s): 822
I. M. Hei, the lead cow pasture architect, is in charge of creating a triangular pasture surrounded by nice white fence rails. She is supplied with N fence segments and must arrange them into a triangular pasture. Ms. Hei must use all the rails to create three sides of non-zero length. Calculating the number of different kinds of pastures, she can build that enclosed with all fence segments.
Two pastures look different if at least one side of both pastures has different lengths, and each pasture should not be degeneration.
The first line of each test case contains an integer N. (1 <= N <= 15)
The next line contains N integers li indicating the length of each fence segment. (1 <= li <= 10000)
3
2 3 4
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
using namespace std; struct node
{
int a,b,c;
node(){a=b=c=0;}
node(int aa,int bb,int cc):a(aa),b(bb),c(cc){} bool operator < (const node &tmp) const
{
if(a!=tmp.a) {return a<tmp.a;}
else if(b!=tmp.b) {return b<tmp.b;}
else {return c<tmp.c;}
} bool operator == (const node &tmp) const
{
return (a==tmp.a && b==tmp.b && c==tmp.c);
}
node operator + (const node &tmp) const
{
int aa=a+tmp.a,bb=b+tmp.b,cc=c+tmp.c;
if(aa>cc) {swap(aa,cc);}
if(bb>cc) {swap(bb,cc);}
if(aa>bb) {swap(aa,bb);}
return node(aa,bb,cc);
}
}; int isok(const node &tmp)
{
return (tmp.a+tmp.b>tmp.c);
} set<node> s[2];
vector<int> myv; int main()
{
int x,t,n,i;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
myv.clear();
for(i=0;i<n;i++)
{
scanf("%d",&x);
myv.push_back(x);
}
s[0].clear();
s[0].insert(node()); int a=0,b=1;
set<node>::iterator it;
for(i=0;i<n;i++)
{
s[b].clear();
for(it=s[a].begin();it!=s[a].end();++it)
{
s[b].insert(*it+node(myv[i],0,0));
s[b].insert(*it+node(0,myv[i],0));
s[b].insert(*it+node(0,0,myv[i]));
}
swap(a,b);
}
int ans=0;
for(it=s[a].begin();it!=s[a].end();++it)
{
if(isok(*it)) ++ans;
}
printf("%d\n",ans);
}
return 0;
}
hdu 4277 USACO ORZ (暴力+set容器判重)的更多相关文章
- HDU 4277 USACO ORZ(暴力+双向枚举)
USACO ORZ Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 4277 USACO ORZ(DFS暴搜+set去重)
原题代号:HDU 4277 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4277 原题描述: USACO ORZ Time Limit: 5000/1 ...
- hdu 4277 USACO ORZ dfs+hash
USACO ORZ Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Proble ...
- hdu 4277 USACO ORZ DFS
USACO ORZ Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu 4277 USACO ORZ
没什么好方法,只能用dfs了. 代码如下: #include<iostream> #include<cstring> #include<cstdio> #inclu ...
- hdu 4277 USACO ORZ(dfs+剪枝)
Problem Description Like everyone, cows enjoy variety. Their current fancy is new shapes for pasture ...
- hdu 4277 USACO ORZ (dfs暴搜+hash)
题目大意:有N个木棒,相互组合拼接,能组成多少种不同的三角形. 思路:假设c>=b>=a 然后枚举C,在C的dfs里嵌套枚举B的DFS. #include <iostream> ...
- hdu 4277 USACO ORZ (Dfs)
题意: 给你n个数,要你用光所有数字组成一个三角形,问能组成多少种不同的三角形 时间分析: 3^15左右 #include<stdio.h> #include<set> usi ...
- hdu 5012 bfs --- 慎用STL 比方MAP判重
http://acm.hdu.edu.cn/showproblem.php?pid=5012 发现一个问题 假设Sting s = '1'+'2'+'3'; s!="123"!!! ...
随机推荐
- php 异常捕获
1 首先是try,catch <?php $path = "D:\\in.txt"; try //检测异常 { file_open($path); } catch(Excep ...
- linux 命令行更新sdk
./android list sdk --proxy-host android-mirror.bugly.qq.com --proxy-port 8080 --no-ui -a -s ./androi ...
- 转: pthread_detach()函数
创建一个线程默认的状态是joinable. 如果一个线程结束运行但没有被join,则它的状态类似于进程中的Zombie Process,即还有一部分资源没有被回收(退出状态码). 所以创建线程者应该调 ...
- vim下编写html的超级利器emmet
GitHub:里面有详细的文档说明 https://github.com/mattn/emmet-vim 下载地址: http://www.vim.org/scripts/script.php?scr ...
- Practice: Process logs with Apache Hadoop
http://www.ibm.com/developerworks/library/os-log-process-hadoop/ Analyzing Apache logs with Apache P ...
- js 中比较 undefined
// x has not been declared before if (typeof x === 'undefined') { // evaluates to true without error ...
- 解决rsyslog 断电或者被kill 重发问题
$InputFilePersistStateInterval 1 Specifies how often the state file shall be written when processing ...
- sigaction 用法实例
sigaction函数的功能是检查或修改与指定信号相关联的处理动作(可同时两种操作). 他是POSIX的信号接口,而signal()是标准C的信号接口(如果程序必须在非POSIX系统上运行,那么就应该 ...
- 使用Horner法则计算多项式的值
计算Pn(x) = an * x^n + an-1 * x^(n-1) + ... + a1 * x + a0 直接计算,需要做的乘法次数 1+2+3+……+n = n(1+n)/2 = O(n2) ...
- mysql优化整理(索引)
什么是索引? 索引是表记录的单个或多个字段重新组织的一种方法,其目的是提高数据库的查询速度,本质上就是一种数据结构. 索引的类型:primary(主键).secondary(其他) 索引的数据结构 I ...