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"!!! ...
随机推荐
- P1337 fibonacci数列(tyvj)
http://www.tyvj.cn/p/1337 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 著名的斐波那契数列f[n]=1 ...
- 真正的手机破解wifi密码,aircrack-ng,reaver,仅限mx2(BCM4330芯片)
仅限mx2(BCM4330芯片),mx可能有戏没测试(BCM4329?),mx3不行. PS:原生安卓应用,非虚拟机 reaver,不知道是啥的看这里http://tieba.baidu.com/p/ ...
- uva 10020 Minimal coverage
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- [LeetCode 111] - 二叉树的最小深度 (Minimum Depth of Binary Tree)
问题 给出一棵二叉树,找出它的最小深度. 最小深度是指从根节点沿着最短路径下降到最近的叶子节点所经过的节点数. 初始思路 不难看出又是一个需要层次遍历二叉树的题目,只要在112基础上作出简单修改即可得 ...
- 位运算反(~)与(&)异或(^)或(|)右移(>>)左移(<<)
原文:位运算反(~)与(&)异或(^)或(|)右移(>>)左移(<<) 先知道这两个二进制数据的特点: 1=0000 0000 0000 0000 0000 000 ...
- android数据保存
永久保存数据的方法:1.Shared Preferences 以键值对的形式存储基本数据类型( booleans, floats, ints, longs, and strings),存储的数据在限制 ...
- [置顶] Android系统移植与调试之------->如何修改Android设备添加3G上网功能
1.首先先来看一下修改前后的效果对比图 step1.插上3G设备前 step2.插上3G设备后,获取信号中.... step3.插上3G设备后,获取到信号 step4.使用3G信号浏览网页 2.下面讲 ...
- linux串口驱动分析——发送数据
一.应用程序中write函数到底层驱动历程 和前文提到的一样,首先先注册串口,使用uart_register_driver函数,依次分别为tty_register_driver,cdev_init函数 ...
- 如何在Windows下使用matplotlib
在开始之前,向matplotlib的创造者,John D. Hunter表示崇高的敬意,和无尽的怀念. (John D. Hunter 1968-2012) matplotlib是一个给予Python ...
- HDU_2016——数据的交换输出
Problem Description 输入n(n<100)个数,找出其中最小的数,将它与最前面的数交换后输出这些数. Input 输入数据有多组,每组占一行,每行的开始是一个整数n,表示这 ...