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"!!! ...
随机推荐
- memcpy造成其他变量值改变
以前C/C++遇到过很多很多的问题,有时候费了很久很久时间,很大很大的努力才解决.但是都没有记录下来,现在想想以前的遇到的问题,只知道这样的事情发生过,至于是什么问题,一点印象都没有了.所以遇 ...
- 转:关于copy_to_user()和copy_from_user()的一些用法
一.Copy_to_user( to, &from, sizeof(from)) To:用户空间函数 (可以是数组) From:内核空间函数(可以是数组) sizeof(from):内核空间 ...
- SVM的点滴
SVM 1. 普通SVM的分类函数可表示为: 其中ai为待优化参数,物理意义即为支持向量样本权重,yi用来表示训练样本属性,正样本或者负样本,为计算内积的核函数,b为待优化参数. 其优化目标函数为: ...
- android上传图片至服务器
本实例实现了android上传手机图片至服务器,服务器进行保存 服务器servlet代码publicvoid doPost(HttpServletRequest request, HttpServle ...
- 一个简单的以User权限启动外部应用程序
BOOL ExecuteAsUser(LPCWSTR lpszUserName, LPCWSTR lpszPassword, LPCWSTR lpszApplication, LPCWSTR lpsz ...
- COJ 0024 N皇后问题
N皇后问题 难度级别:B: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 在N*N的方格棋盘放置N个皇,使得它们不相互攻击(即任意2个 ...
- win7 共享
1.取得IP 3. 输入 用户名 和密码就可以了
- LeetCode-Word LadderII
Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...
- MD中bitmap源代码分析--入题概述
在MD模块中,各级raid都使用的一份bitmap的源码,也就是说共用一种bitmap的流程,下面以raid1的使用为例来分析bitmap的工作原理. 在使用raid1磁盘阵列的时候,对于数据的可靠性 ...
- JS点击按钮弹出窗口
由于没有系统学习过JS,遇到一个需求:点击按钮,弹出一个独立的窗口. 在网上百度了一下,并没有找到满意的结果,最重要的是各种方法很复杂.最终,仔细研究了一下,原来只是需要只要一个简单的函数就能满足自己 ...