`
java-mans
  • 浏览: 11454640 次
文章分类
社区版块
存档分类
最新评论

10012 How Big Is It?(****)

 
阅读更多
/*
题意:一堆小球,要求使用最小的矩形将它们全部装起来。
要求小球必须接地,至少与其他一个小球相邻
思路:涉及到状态转移,用到动态规划思想。原来通过深搜,剪枝结果WA,后来想到两个相邻小球半径相差很大的情况,于是没有了做题思路。看别人代码后,搜索中添加两个数组,A[i]表示第i个小球的半径大小,c[i]表示第i个小球排完后右边界最远的位置。于是有状态转移方程:  c[i]=max(c[j]+2*sqrt(A[j]*A[i])|j为第i个之间的小球),最后需要检查一次左边界和右边界,可能出现左边界左移的情况,所以只要让c[i]都加上左移的距离即可!
*/

//错误代码:
#include <cstdio>
#include <cstring>
#include <cmath>
bool visit[10];
int T,n;
double radii[10];
double min;
int A[10],result[10];
void dfs(int now,int dep,double length)
{
	A[dep-1]=now;
	if(length>=min) return;
	if(dep==n)
	{
		if(length+radii[now]<min)
		{
			min=length+radii[now];
			memcpy(result,A,sizeof(A));
		}
	}
	for(int i=0;i<n;i++)
	{
		if(!visit[i])
		{
			visit[i]=1;
			dfs(i,dep+1,length+2*sqrt(radii[now]*radii[i]));
			visit[i]=0;
		}

	}
}
int main()
{
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d",&n);
		for(int i=0;i<n;i++)
			scanf("%lf",&radii[i]);
		min=1e10;
		memset(visit,0,sizeof(visit));
		for(int i=0;i<n;i++)
		{
			visit[i]=1;
			dfs(i,1,radii[i]);
		}
		for(int i=0;i<n;i++)
			printf("%d ",result[i]);
		printf("\n");
		printf("%.3lf\n",min);
	}
	return 0;
}


//正解:
#include <cstdio>
#include <cmath>
#include <cstring>
double A[10],c[10];
double radii[10];
int n;
bool visit[10];
double ans;
void dfs(int cur)
{
	if(cur==n)
	{
		double move=0.0;
		for(int i=0;i<n;i++)
		{
			double temp=A[i]-c[i];
			if(temp>move)
				move=temp;
		}
		for(int i=0;i<n;i++)
			c[i]+=move;
		double res=0.0;
		for(int i=0;i<n;i++)
		{
			double temp=A[i]+c[i];
			if(temp>res)
				res=temp;
		}
		if(res<ans)
			ans=res;
		return;
	}
	for(int i=0;i<n;i++)
		if(!visit[i])
		{
			visit[i]=1;
			A[cur]=radii[i];
			c[cur]=0.0;
			for(int j=0;j<cur;j++)
			{
				double temp=c[j]+2*sqrt(A[cur]*A[j]);
				if(c[cur]<temp)
					c[cur]=temp;
			}
			dfs(cur+1);
			visit[i]=0;
		}
}
int main()
{
	freopen("data.in","r",stdin);
	int T;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d",&n);
		for(int i=0;i<n;i++)
			scanf("%lf",&radii[i]);
		memset(visit,0,sizeof(visit));
		ans=1e10;
		for(int i=0;i<n;i++)
		{
			A[0]=radii[i];
			c[0]=radii[i];
			visit[i]=1;
			dfs(1);
			visit[i]=0;
		}
		printf("%.3lf\n",ans);
	}
}


分享到:
评论

相关推荐

    How big is that?-crx插件

    语言:English 多大? “那有多大?” 允许您在线选择任何测量,并查看此测量的真实程度。 在使用扩展之前,您需要将其校准到您的显示器。 这将确保所有显示的测量都具有正确的尺寸。在此之后,只需选择您在线找到的...

    Real-Time Big Data Analytics: Emerging Architecture

    Real-Time Big Data Analytics: Emerging Architecture by Mike Barlow 2013-02-25 First release Table of Contents 1. Introduction 2. How Fast Is Fast?...6. How Big Is Big? 7. Part of a Larger Trend

    《Modern Aircraft Design Techniques》 W.H. Mason

    Table of Contents 1. Introduction to Aircraft Design ...5. Vehicle Sizing – how big is it? 6. Current typical design process. 7. MDO – the modern computational design approach 8. References

    Understanding Big Data

    You’ll get a primer on Hadoop and how IBM is hardening it for the enterprise, and learn when to leverage IBM InfoSphere BigInsights (Big Data at rest) and IBM InfoSphere Streams (Big Data in motion)...

    You’ve Got To Find What You Love -- steve jobs

    乔布斯在斯坦福大学的演讲稿 I am honored to be with you today at your commencement from one of the finest universities in the world. I never graduated from ...That’s it. No big deal. Just three stories.

    大数据.pptx

    大数据究竟有多"大" How big is it? 海量 巨型 TB? PB? 主观标签 大数据全文共46页,当前为第4页。 大数据究竟有多"大" How big is it? 各大公司的业务量 大数据全文共46页,当前为第5页。 大数据特点 大数据全文...

    Big.Data.Using.SMART.Big.Data.Analytics.and.Metrics.To.Make.Better.Decisions

    We all need to know what it is and how it works - that much is obvious. But is a basic understanding of the theory enough to hold your own in strategy meetings? Probably. But what will set you apart ...

    My Botnet is Bigger than Yours (Maybe, Better than Yours) :why size estimates remain challenging

    Yet, time and time again, one lingering question remains: how big are today’s botnets? We hear widely diverging answers. In fact, some may argue, contradictory. The root cause for this confusion is ...

    Building Your Next Big Thing with Google Cloud Platform(Apress,2015)

    Building Your Next Big Thing with Google Cloud Platform shows you how to take advantage of the Google Cloud Platform technologies to build all kinds of cloud-hosted software and services for both ...

    Big Data Bootcamp(Apress,2014)

    Big Data Bootcamp explains what big data is and how you can use it in your company to become one of tomorrow's market leaders. Along the way, it explains the very latest technologies, companies, and ...

    八年级英语下期末模拟试题答案.doc

    B: There is a big tree and the children like playing under it. 9A: Where is your pen pal from, Mike? C B: He is from Canada. He can speak English and a little Chinese. 10A: How’s the weather today in...

    Big Data, MapReduce, Hadoop, and Spark with Python

    In addition to giving you deeper insight into how big data processing works, learning about the fundamentals of MapReduce and Hadoop first will help you really appreciate how much easier Spark is to ...

    Big.Data.Opportunities.and.challenges.B00JJSUJKK

    The articles in this ebook aim to give practical guidance for all those who want to understand big data better and learn how to make the most of it. Topics range from big data analysis, mobile big ...

    Big Data_A Very Short Introduction-Oxford University Press(2017).epub

    The aim of this book is to offer an alternative by providing an introduction to how big data works and is changing the world about us; the effect it has on our everyday lives; and the effect it has ...

    Understanding Big Data--IBM

    ll get a primer on Hadoop and how IBM is hardening it for the enterprise and learn when to leverage IBM InfoSphere BigInsights Big Data at rest and IBM InfoSphere Streams Big Data in motion ...

    Big.Data.in.Practice.1119231388

    The best-selling author of Big Data is back, this time with a unique and in-depth insight into how specific companies use big data. Big data is on the tip of everyone's tongue. Everyone understands ...

    sql_on_big_data.pdf

    It discusses how SQL is not just being used for structured data but also for semistructured and streaming data. Big data tools are also rapidly evolving in the operational data space. The book ...

    SQL.on.Big.Data.Technology.Architecture.and.Innovation

    ―an understanding of the internals and how the existing Hive engine is built and how it is evolving continually to support new features and provide lower latency on queries Interactive Architectures...

    God works. 上帝的安排。

    God works. 上帝的安排。 Not so bad. 不错。 No way! 不可能! Don't flatter me....Hope so....Go down to business....I'm not going....Does it serve your purpose?...I don't care....How big of you! 你真棒!

Global site tag (gtag.js) - Google Analytics