1730: 通信基站

Time Limit: 1 Sec  Memory Limit:
128 MB

Submit: 28  Solved: 11



SubmitStatusWeb
Board

Description

Input

Output

Sample Input

  1. 2
  2. 2 1 1
  3. 0 0
  4. 4 4
  5. 3 100 1
  6. 0 0
  7. 1 1
  8. 500 500

Sample Output

  1. 2.00
  2. 201.41
  1.  
  1. 原题链接
  1. 这次真是学到了,看得大神的代码,思路真是不错,最也就八个点,每个点有建与不建两种状态,所以最都也就是2^8种情况,我们每次列举有多少个地点建基站,然后就进行全排列,直到所有的全排列都列举一遍,prev_permutations+1s+n+1)记录所有的全排列,然后再进行搜索,dfs查找出当前方案下最小的花费,搜索的时候要进行回溯
  1.  
  1. #include<cstdio>
  2. #include<cstring>
  3. #include<cmath>
  4. #include<iostream>
  5. #include<algorithm>
  6. using namespace std;
  7. #define INF 0x3f3f3f3f
  8. int a[100],b[100];
  9. int ta,tb;
  10. double x[11],y[11];
  11. double used[100],sum;
  12. double Cr,Cs;
  13. int n,s[100];
  14. double dis(int a,int b)
  15. {
  16. 	return sqrt((x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]));
  17. }
  18. void dfs(int pos)//pos记录已经覆盖的没有基站的数量
  19. {
  20. 	if(pos==ta+1)
  21. 	{
  22. 		double res=0;
  23. 		for(int i=1;i<=n;i++)
  24. 		res+=used[i];
  25. 		sum=min(res,sum);//sum表示当前方案下最小的距离
  26. 		return ;
  27. 	}
  28. 	for(int j=1;j<=tb;j++)
  29. 	{
  30. 		double d=dis(b[j],a[pos]);
  31. 		double val=used[j];
  32. 		used[j]=max(used[j],d);//要用max,因为必须多个点全部覆盖
  33. 		dfs(pos+1);
  34. 		used[j]=val;//这个点可以不进行扩张
  35. 	}
  36. }
  37. double solve(int cnt)
  38. {
  39. 	double res=Cs*cnt;
  40. 	ta=tb=0;
  41. 	for(int i=1;i<=n;i++)
  42. 	{
  43. 		if(s[i]) b[++tb]=i;
  44. 		else a[++ta]=i;
  45. 		used[i]=0;
  46. 	}
  47. 	sum=0;
  48. 	if(cnt!=n)
  49. 	sum=INF;//如果每个点都建立基站,sum就无意义
  50. 	dfs(1);//共有ta个点没有基站,所以其他基站要进行覆盖
  51. 	return res+sum*Cr;
  52. }
  53. int main()
  54. {
  55. 	int t;
  56. 	scanf("%d",&t);
  57. 	while(t--)
  58. 	{
  59. 		scanf("%d%lf%lf",&n,&Cs,&Cr);
  60. 		for(int i=1;i<=n;i++)
  61. 		scanf("%lf%lf",&x[i],&y[i]);
  62. 		double ans=INF;
  63. 		for(int i=1;i<=n;i++)
  64. 		{
  65. 			memset(s,0,sizeof(s));
  66. 			for(int j=1;j<=i;j++)
  67. 			s[j]=1;
  68. 			do
  69. 			{
  70. 				ans=min(ans,solve(i));
  71. 			}while(prev_permutation(s+1,s+n+1));//判断是否已经完成所有的全排列
  72. 		}
  73. 		printf("%.2f\n",ans);
  74. 	}
  75. 	return 0;
  76. }

zzulioj--1730--通信基站(全排列+dfs)(好题)的更多相关文章

  1. for循环枚举法,全排列+dfs,补充浮点数注意事项

    其实这个题目我一直没想好应该叫什么,就是在做蓝桥杯的时候会遇到很多的题,给你一等式,abcdef...分别是1-9(||12||15)不重复问你有几种方案? 我之前一直都是用的for循环在做,听说这叫 ...

  2. 咸鱼的ACM之路:DFS水题集

    DFS的核心就是从一种状态出发,转向任意的一个可行状态,直到达到结束条件为止.(个人理解) 下面全是洛谷题,毕竟能找到测试点数据的OJ我就找到这一个....在其他OJ上直接各种玄学问题... P159 ...

  3. POJ 1321 棋盘问题(DFS板子题,简单搜索练习)

    棋盘问题 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 44012   Accepted: 21375 Descriptio ...

  4. poj1564 Sum It Up dfs水题

    题目描述: Description Given a specified total t and a list of n integers, find all distinct sums using n ...

  5. 【转帖】2019年中国5G行业细分市场发展现状和市场前景分析 通信基站数量快速增长

    2019年中国5G行业细分市场发展现状和市场前景分析 通信基站数量快速增长 中国有 600多万个基站 平均每200个人 一个基站.. 一个基站十万块钱的话 相当于 每个人 需要分摊 500块钱. ht ...

  6. 通信基站(dfs回溯,思维)

    Description Input Output

  7. hdu 1045:Fire Net(DFS经典题)

    Fire Net Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  8. 组合数学(全排列)+DFS CSU 1563 Lexicography

    题目传送门 /* 题意:求第K个全排列 组合数学:首先,使用next_permutation 函数会超时,思路应该转变, 摘抄网上的解法如下: 假设第一位是a,不论a是什么数,axxxxxxxx一共有 ...

  9. 【wikioi】1229 数字游戏(dfs+水题)

    http://wikioi.com/problem/1229/ 赤裸裸的水题啊. 一开始我认为不用用完全部的牌,以为爆搜会tle.. 可是我想多了. 将所有状态全部求出,排序后暴力判断即可. (水题有 ...

随机推荐

  1. 使用super实现类的继承

    查看一个类继承了哪些类可以用__bases__方法查看 class People:   def __init__(self,name,age,sex):  self.name=name self.ag ...

  2. JAVA趣味逻辑算法

    /**已知4位同学中的一位数学考了100分,当小李询问这4位是谁考了100分时,4个人的回答如下: A说:不是我. B说:是C C说:是D. D说:他胡说. 已知三个人说的是真话,一个人说的是假话.现 ...

  3. Zabbix 客户端安装教程(第二篇)

    Zabbix 客户端安装教程 blog地址:http://www.cnblogs.com/caoguo [root@localhost ~]# yum install -y gcc make [roo ...

  4. IOS7升级攻略

    1) Select the main view, set the background color to black (or whatever color you want the status ba ...

  5. PHP 之simple_html_dom实现网页数据采集

    <?php set_time_limit(0); include './simple_html_dom.php'; $url = 'https://price.pcauto.com.cn/pri ...

  6. 删除Git服务器文件但是保留本地文件

    参考: https://blog.csdn.net/u012804886/article/details/83059315 https://www.cnblogs.com/wfsovereign/p/ ...

  7. [luogu2591 ZJOI2009] 函数

    传送门 Solution 画图找规律.. Code //By Menteur_Hxy #include <cstdio> #define min(a,b) ((a)>(b)?(b): ...

  8. MySQL的分组和排序

    分组操作 select count(id) from userinfo group by pat(id); -- 聚合函数: --count --max --sum --avg ---如果对于二次函数 ...

  9. 面试题:你能写一个Vue的双向数据绑定吗?

    在目前的前端面试中,vue的双向数据绑定已经成为了一个非常容易考到的点,即使不能当场写出来,至少也要能说出原理.本篇文章中我将会仿照vue写一个双向数据绑定的实例,名字就叫myVue吧.结合注释,希望 ...

  10. Problem 34

    Problem 34 https://projecteuler.net/problem=34 145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 1 ...