USACO ORZ

Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Problem Description
Like everyone, cows enjoy variety. Their current fancy is new shapes for pastures. The old rectangular shapes are out of favor; new geometries are the favorite.
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.
 
Input
The first line is an integer T(T<=15) indicating the number of test cases.
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)
 
Output
For each test case, output one integer indicating the number of different pastures.
 
Sample Input
1
3
2 3 4
 
Sample Output
1
 
Source
题意:用所有点组成三角形,问不同的个数;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<bitset>
#include<set>
#include<map>
#include<time.h>
using namespace std;
#define LL long long
#define bug(x) cout<<"bug"<<x<<endl;
const int N=2e5+,M=1e6+,inf=1e9+;
const LL INF=1e18+,mod=1e9+;
const double eps=(1e-),pi=(*atan(1.0)); int num[N],n;
struct hashnum
{
const static int si=1e6+;
vector<LL>v[];
void add(LL x)
{
LL temp=x;
x%=si;
for(int i=;i<v[x].size();i++)
if(v[x][i]==temp)return;
v[x].push_back(temp);
}
}hs;
void dfs(int pos,int a,int b,int c)
{
if(pos>n)
{
if(a>b)swap(a,b);
if(b>c)swap(b,c);
if(a>b)swap(a,b);
if(a+b>c)
{
hs.add(1LL*a*+b);
}
return;
}
dfs(pos+,a+num[pos],b,c);
dfs(pos+,a,b+num[pos],c);
dfs(pos+,a,b,c+num[pos]);
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
for(int i=;i<=hs.si;i++)
hs.v[i].clear();
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&num[i]);
dfs(,,,);
int ans=;
for(int i=;i<hs.si;i++)
ans+=hs.v[i].size();
printf("%d\n",ans);
}
return ;
}

hdu 4277 USACO ORZ dfs+hash的更多相关文章

  1. hdu 4277 USACO ORZ DFS

    USACO ORZ Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  2. HDU 4277 USACO ORZ(DFS暴搜+set去重)

    原题代号:HDU 4277 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4277 原题描述: USACO ORZ Time Limit: 5000/1 ...

  3. HDU 4277 USACO ORZ(暴力+双向枚举)

    USACO ORZ Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  4. hdu 4277 USACO ORZ (dfs暴搜+hash)

    题目大意:有N个木棒,相互组合拼接,能组成多少种不同的三角形. 思路:假设c>=b>=a 然后枚举C,在C的dfs里嵌套枚举B的DFS. #include <iostream> ...

  5. hdu 4277 USACO ORZ(dfs+剪枝)

    Problem Description Like everyone, cows enjoy variety. Their current fancy is new shapes for pasture ...

  6. hdu 4277 USACO ORZ (Dfs)

    题意: 给你n个数,要你用光所有数字组成一个三角形,问能组成多少种不同的三角形 时间分析: 3^15左右 #include<stdio.h> #include<set> usi ...

  7. hdu 4277 USACO ORZ

    没什么好方法,只能用dfs了. 代码如下: #include<iostream> #include<cstring> #include<cstdio> #inclu ...

  8. HDU4277 USACO ORZ(dfs+set)

    Problem Description Like everyone, cows enjoy variety. Their current fancy is new shapes for pasture ...

  9. hdu4277 USACO ORZ

    USACO ORZ Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

随机推荐

  1. oracle安装教程

    首先下载oracle 12c的安装包(一共有两个组成),下载完之后将两个压缩文件解压到同一个目录下 https://pan.baidu.com/s/1ydsClsHv04RAwaoGmHrFVQ ht ...

  2. SQL Server 2008作业失败:无法确定所有者是否有服务器访问权限

    转自:http://www.mzwu.com/article.asp?id=3592 下午准备将服务器数据导一份到本地,连上服务器找数据库备份文件发现最后一次备份是7月1日,竟然十几天没生成新备份,查 ...

  3. db2look 工具

    db2look -d sample -m > db2look_stat.out

  4. GitHub 设置首页显示 404 There isn't a GitHub Pages site here.

    问题如题! 能使用的必要条件是: 1.创建的仓库 Code 中 必须 有 README.md 文件,内容自定 2.设置模板在仓库中 Settings -->GitHub Pages --> ...

  5. try 和 catch 和 finally

    try块中出现异常走进catch,异常后面的代码不会再被执行:finally块里try和catch执行完后要执行的代码,且一定会执行. 在释放资源的时候,不要多个放在一个try块里面. 流的关闭顺序: ...

  6. Spring Boot 你所不知道的超级知识学习路线清单

    因而 Spring Boot 应用本质上就是一个基于 Spring 框架的应用,它是 Spring 对“约定优先于配置”理念的最佳实践产物,它能够帮助开发者更快速高效地构建基于 Spring 生态圈的 ...

  7. ssl证书

    个人理解: 客户端第一次连接服务端的时候,服务端就把证书(中的公钥)给了客户端,客户端验证证书中的公钥是否和本地的公钥一致(客户端一般都会内置类似AC的具有公信力的证书颁发机构), 之后的请求每次请求 ...

  8. js篇-判断数组对象中是否含有某个值,并返回该条数据

    项目背景需求是: 已知: var a=[{name:'jenny',age:18},{name:'john',age:19},{name:'jack',age:20}] var b ='jenny' ...

  9. [js]js设计模式-修改原型

    参考 操作原型 - 给原型添加属性 - 方法1: Fn.prototype.sum=function{} - 方法2: Fn.prototype={} //constructor指向了Object的原 ...

  10. Echarts-图表根据值的不同展示成不同的颜色

    series : [        {            name:'直接访问',            type:'bar',            barWidth: '60%',      ...