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

Problem Description
Zu Chongzhi (429–500) was a prominent Chinese mathematician and astronomer during the Liu Song and Southern Qi Dynasties. Zu calculated the value ofπ to the precision of six decimal places and for a thousand years thereafter no subsequent mathematician computed a value this precise. Zu calculated one year as 365.24281481 days, which is very close to 365.24219878 days as we know today. He also worked on deducing the formula for the volume of a sphere.

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.

 
Input
There are no more than 10 test cases. For each case:

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.

 
Output
For each test case, output the maximum total area of triangles Zu could make. Round the result to 2 digits after decimal point. If Zu couldn't make any triangle, print 0.00 .
 
Sample Input
3
1 1 20
7
3 4 5 3 4 5 90
0
 
Sample Output
0.00
13.64

题意  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搜索 枚举种数的更多相关文章

  1. 蓝桥杯dfs搜索专题

    2018激光样式 #include<bits/stdc++.h> using namespace std; /* dfs(i) 第i个激光机器 有两种选择:vis[i-1] == 0 时 ...

  2. LeetCode DFS搜索与回溯专题

    DFS + 回溯专题 17. 电话号码的字母组合 迭代也可以实现搜索 循环改写dfs搜索的写法: 例如 C++写法 class Solution { public: vector<string& ...

  3. hdu 1312:Red and Black(DFS搜索,入门题)

    Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  4. [ZOJ 1011] NTA (dfs搜索)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1011 题目大意:在一棵树上,给你起始状态,问你能否到达终止状态. ...

  5. [ZOJ 1003] Crashing Balloon (dfs搜索)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3 题目大意:给你a,b两个数,问当b由约数1到100组成时,a能否由其 ...

  6. HDU 1312:Red and Black(DFS搜索)

      HDU 1312:Red and Black Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & ...

  7. hihocoder 1050 树中的最长路(动态规划,dfs搜索)

    hihocoder 1050 树中的最长路(动态规划,dfs搜索) Description 上回说到,小Ho得到了一棵二叉树玩具,这个玩具是由小球和木棍连接起来的,而在拆拼它的过程中,小Ho发现他不仅 ...

  8. sdut 2152:Balloons(第一届山东省省赛原题,DFS搜索)

    Balloons Time Limit: 1000MS Memory limit: 65536K 题目描述 Both Saya and Kudo like balloons. One day, the ...

  9. 蓝桥杯 历届试题 剪格子(dfs搜索)

    历届试题 剪格子 时间限制:1.0s   内存限制:256.0MB 问题描述 如下图所示,3 x 3 的格子中填写了一些整数. +--*--+--+ |* || +--****--+ ||* | ** ...

随机推荐

  1. 简单介绍什么是协程及其在ES6中的实现方式

    协程,英文名coroutine,是一种执行过程可以被暂停和恢复的方法.各个协程之间相互协作完成一个任务. 让我们来看一个关于发挥协程作用的例子.假定我们有一个生产者和消费者的关系,生产者创建物品并将物 ...

  2. 7.18 DP考试解题报告

    今天的考试真的是天崩地裂,写了的三个题全炸...然而谁叫我弱+不注意细节呢???真的要扇耳光... T1:题意:一段区间的高度为这个区间中高度的最小值,给定n个宽度,求每个宽度的期望高度 40% :算 ...

  3. LODOP打印控件示例

    一.lodop打印预览效果图 LODOP.PRINT_SETUP();打印维护效果图 LODOP.PREVIEW();打印预览图 二.写在前面 最近项目用到了LODOP的套打,主要用到两个地方,一是物 ...

  4. 进程间通信 ipcs

    在linux系统上借助ipcs命令可以方便地查看进程间通信状态 操作系统:centos7.3 x86_64 应用软件: oracle12c

  5. FPGA设计思想与技巧(转载)

    题记:这个笔记不是特权同学自己整理的,特权同学只是对这个笔记做了一下完善,也忘了是从那DOWNLOAD来的,首先对整理者表示感谢.这些知识点确实都很实用,这些设计思想或者也可以说是经验吧,是很值得每一 ...

  6. 在一个终端后台运行的进程在新的终端中使用job不会被发现

    我在一个终端后台运行了一个程序.之后由于工作需要又新开了一个新的终端.在新的终端中,我想查看后台程序的运行状态,输入jobs时,发现没有后台任务运行.难道我的程序死掉了?我接着top了下,发现我的后台 ...

  7. JavaScript学习点滴 call、apply的区别

    对于apply和call两者在作用上是相同的,但两者在参数上有区别的.     1.call call 方法 调用一个对象的一个方法,以另一个对象替换当前对象. call([thisObj[,arg1 ...

  8. Android OpenGL ES 入门系列(二) --- 环境搭建

    转载请注明出处 本文出自Hansion的博客 本章介绍如何使用GLSurfaceView和GLSurfaceView.Renderer完成在Activity中的最简单实现. 1.在AndroidMan ...

  9. java基础之关键字static

        在java当中有很多关键字,static便是其中一个,它很普通但我们经常需要运用到它,所以要了解static是非常有必要的.   鉴于本人知识结构有限,若有错误忘不吝赐教,甚为感谢.   一. ...

  10. 【Java框架型项目从入门到装逼】第七节 - 学生管理系统项目搭建

    本次的教程是打算用Spring,SpringMVC以及传统的jdbc技术来制作一个简单的增删改查项目,对用户信息进行增删改查,就这么简单. 1.新建项目 首先,打开eclipse,新建一个web项目. ...