HDU5135 dfs搜索 枚举种数
Little Zu Chongzhi's Triangles
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 2195 Accepted Submission(s): 1262
It is said in some legend story books that when Zu was a little boy, he liked mathematical games. One day, his father gave him some wood sticks as toys. Zu Chongzhi found a interesting problem using them. He wanted to make some triangles by those sticks, and he wanted the total area of all triangles he made to be as large as possible. The rules were :
1) A triangle could only consist of 3 sticks.
2) A triangle's vertexes must be end points of sticks. A triangle's vertex couldn't be in the middle of a stick.
3) Zu didn't have to use all sticks.
Unfortunately, Zu didn't solve that problem because it was an algorithm problem rather than a mathematical problem. You can't solve that problem without a computer if there are too many sticks. So please bring your computer and go back to Zu's time to help him so that maybe you can change the history.
The first line is an integer N(3 <= N<= 12), indicating the number of sticks Zu Chongzhi had got. The second line contains N integers, meaning the length of N sticks. The length of a stick is no more than 100. The input ends with N = 0.
题意 n条边 组成三角形使面积和尽可能大
解析 由于n比较小加上数据有点水 可以枚举所有情况 进行计算
注 枚举过程情况会有重复 但时间上还是过了 相当于 先从n个中 拿n/3*3条边 再从n/3*3中拿3条边 再从(n/3-1)*3里面再拿3条边。。。用组合数计算得到的种数重复情况是一样的
我在说什么QAQ 我有点懵X 不要看了 当我没说 打扰了
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;
const int maxn= ;
const double eps= 1e-;
const int inf = 0x3f3f3f3f;
const int mod =;
typedef long long ll;
typedef long double ld;
int n,kase;
double ans;
int visit[maxn];
double a[maxn];
double judge(double x,double y,double z) //返回当前三条边 组成三角形的面积
{
if(x>y)
swap(x,y);
if(x>z)
swap(x,z);
if(y>z)
swap(y,z);
if(x+y<=z) //不能组成三角形 返回0
return 0.0;
else
{
double p=(x+y+z)/; //海伦公式
return sqrt(p*(p-x)*(p-y)*(p-z));
}
}
void dfs(int x,double y) //当前枚举x个三角形 总面积为y
{
ans=max(ans,y);
if(x==n/)
{
x=;
//printf("%d %lf\n",kase++,y);
y=0.0;
}
for(int i=; i<=n; i++)
{
if(visit[i]==)
continue;
for(int j=i+; j<=n; j++)
{
if(visit[j]==)
continue;
for(int k=j+; k<=n; k++)
{
if(visit[k]==)
continue;
else
{
visit[i]=,visit[j]=,visit[k]=;
dfs(x+,y+judge(a[i],a[j],a[k]));
visit[i]=,visit[j]=;visit[k]=;
}
}
}
}
}
int main()
{
while(scanf("%d",&n)!=EOF&&n)
{
for(int i=;i<=n;i++)
{
scanf("%lf",&a[i]);
}
memset(visit,,sizeof(visit));
ans=0.0;
//kase=1;
dfs(,0.0);
printf("%.2lf\n",ans);
}
}
HDU5135 dfs搜索 枚举种数的更多相关文章
- 蓝桥杯dfs搜索专题
2018激光样式 #include<bits/stdc++.h> using namespace std; /* dfs(i) 第i个激光机器 有两种选择:vis[i-1] == 0 时 ...
- LeetCode DFS搜索与回溯专题
DFS + 回溯专题 17. 电话号码的字母组合 迭代也可以实现搜索 循环改写dfs搜索的写法: 例如 C++写法 class Solution { public: vector<string& ...
- hdu 1312:Red and Black(DFS搜索,入门题)
Red and Black Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- [ZOJ 1011] NTA (dfs搜索)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1011 题目大意:在一棵树上,给你起始状态,问你能否到达终止状态. ...
- [ZOJ 1003] Crashing Balloon (dfs搜索)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3 题目大意:给你a,b两个数,问当b由约数1到100组成时,a能否由其 ...
- HDU 1312:Red and Black(DFS搜索)
HDU 1312:Red and Black Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & ...
- hihocoder 1050 树中的最长路(动态规划,dfs搜索)
hihocoder 1050 树中的最长路(动态规划,dfs搜索) Description 上回说到,小Ho得到了一棵二叉树玩具,这个玩具是由小球和木棍连接起来的,而在拆拼它的过程中,小Ho发现他不仅 ...
- sdut 2152:Balloons(第一届山东省省赛原题,DFS搜索)
Balloons Time Limit: 1000MS Memory limit: 65536K 题目描述 Both Saya and Kudo like balloons. One day, the ...
- 蓝桥杯 历届试题 剪格子(dfs搜索)
历届试题 剪格子 时间限制:1.0s 内存限制:256.0MB 问题描述 如下图所示,3 x 3 的格子中填写了一些整数. +--*--+--+ |* || +--****--+ ||* | ** ...
随机推荐
- JAVA多线程统计日志计数时的线程安全及效率问题
最近工作上遇到一个需求:需要根据nginx日志去统计每个域名的qps(Query Per Second,每秒查询率)数据. 解决了日志读取等问题之后,为了写一个尽可能高效的统计模块,我决定用多线程去计 ...
- laravel and lumen 软删除操作
知识都是有联系的,这绝对是真理.作为一名小白,看了一点官方文档,把我自己理解的软删除操作给大家讲讲.有些就是套用官方文档的话. 定义:什么是软删除呢,所谓软删除指的是数据表记录并未真的从数据库删除,而 ...
- IT服务(运维)管理实施的几个要点--序言
IT服务(运维)管理(不是IT运维技术)是IT行业当中相对比较"窄"的一个分支,通常只被金融.电信等大型数据中心的中高层管理人员所关注.但是根据笔者多年从事IT服务和服务管理的经验 ...
- centOS7 mini配置linux服务器(四) 配置jdk
这里简单写一下centos7Mini 安装jdk1.8的全过程. 一.下载jdk,linux版本. 地址:http://www.oracle.com/technetwork/java/javase/ ...
- Android开发之漫漫长途 IX——彻底掌握Binder
该文章是一个系列文章,是本人在Android开发的漫漫长途上的一点感想和记录,我会尽量按照先易后难的顺序进行编写该系列.该系列引用了<Android开发艺术探索>以及<深入理解And ...
- 如何高逼格读取Web.config中的AppSettings
http://edi.wang/post/2015/4/22/how-to-read-webconfig-appsettings-with-bigiblity 先插句题外话,下版本的ASP.NET貌似 ...
- python简单爬虫技术
项目中遇到这个只是点,捣鼓了半天最后没用上,但是大概对爬虫技术有了些许了解 要先 比如: #抓取网页代码 import urllib2 import json url_data = urllib2.u ...
- vue2.0 项目build后资源文件报错404的解决方案
当vue项目build后,我们会看到css.js报错404的问题: 那我们就去找错误原因吧. 首先,查看build后的dist文件目录 可以看出,js.css在index.html的同级目录下: 然后 ...
- 【Java框架型项目从入门到装逼】第八节 - 用EasyUI绘制主界面
1.引入资源包 在上一节中,我们把基本的框架都搭好了,用了Spring,SPringMVC.这一节,我们先来画页面,前端框架采用EasyUI来实现. easyui是一种基于jQuery的用户界面插件集 ...
- [Spark性能调优] 第三章 : Spark 2.1.0 中 Sort-Based Shuffle 产生的内幕
本課主題 Sorted-Based Shuffle 的诞生和介绍 Shuffle 中六大令人费解的问题 Sorted-Based Shuffle 的排序和源码鉴赏 Shuffle 在运行时的内存管理 ...