JZOJ8月10日提高组T2 Fix
JZOJ8月10日提高组T2 Fix
题目
Description
There are a few points on a plane, and some are fixed on the plane, some are not. We want to connect these points by some sticks so that all the points are fixed on the plane. Of course, we want to know the minimum length of the sum of the sticks.

As in the images, the black points are fixed on the plane and red ones are not, which need to be fixed by sticks.
All the points in the left image have been fixed. But the middle one is not, which we need add one stick to fix those four points (the right image shows that stick). Triangle is steady, isn’t it?
Input
The input consists of multiply test cases. The first line of each test case contains one integer, n (1 <= n <= 18), which is the number of points. The next n lines, each line consists of three integers, x, y, c (0 <= x, y < 100). (x, y) indicate the coordinate of one point; c = 1 indicates this point is fixed; c = 0 indicates this point is not fixed. You can assume that no two points have the same coordinate.
The last test case is followed by a line containing one zero, which means the end of the input.
Output
Output the minimum length with six factional digits for each test case in a single line. If you cannot fix all the points, then output “No Solution”.
Sample Input
4
0 0 1
1 0 1
0 1 0
1 1 0
3
0 0 1
1 1 0
2 2 0
0
Sample Output
4.414214
No Solution
Hint
大概意思就是给你一些点,其中一些点是固定的,然后还有一些没有固定的,然后问你固定所有点所用的线段的最小长度是多少。
所谓固定,就是形如三角形的情况,就是两个固定的点向一个未固定的点连两条边,就能把未固定的点固定。
题解
题意
给出\(n\)个点,其中一些点是固定的,然后还有一些没有固定的,问固定所有点所用的线段的最小长度是多少。
定义固定:两个固定的点向一个未固定的点连两条边,就能把未固定的点固定。
分析
可以想到状压\(DP\)来维护状态
如果枚举状态、固定点和连线点的话,将会是\(O(2^n*n^3)\)
思考优化
既然要答案优,就要使得连线点更加靠经固定点
那么排序后扫一遍就可以了
优化至\(O(2^n*n^2)\)
Code
#include<cmath>
#include<cstdio>
#include<algorithm>
#define inf 2147483646.9
using namespace std;
int n,now,fix,op,i,j,k,num,er[20];
double l,f[500005];
struct node1
{
int x,y;
}a[20];
struct node
{
double val;
int id;
}dis[20][20];
double sqr(int x)
{
return 1.0*x*x;
}
bool cmp(node x,node y)
{
return x.val<y.val;
}
int main()
{
while (true)
{
scanf("%d",&n);
if (n==0) break;
now=0;
fix=0;
for (i=1;i<=n;i++)
{
scanf("%d%d%d",&a[i].x,&a[i].y,&op);
if (op==1)
{
fix++;
now+=(1<<(i-1));
}
}
if (fix==n)
{
printf("0.000000\n");
continue;
}
if (fix<2)
{
printf("No Solution\n");
continue;
}
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
dis[i][j].val=sqrt(sqr(a[i].x-a[j].x)+sqr(a[i].y-a[j].y));
dis[i][j].id=j;
}
sort(dis[i]+1,dis[i]+n+1,cmp);
}
for (i=0;i<=n;i++)
er[i]=1<<i;
for (i=1;i<=(1<<n);i++)
f[i]=inf;
f[now]=0;
for (i=now;i<(1<<n);i++)
{
if (f[i]!=inf)
for (j=1;j<=n;j++)
if ((i&(1<<(j-1)))==0)
{
num=0;
l=0;
for (k=1;k<=n;k++)
if ((i&(1<<(dis[j][k].id-1)))!=0)
{
num++;
l+=dis[j][k].val;
if(num==2)
{
f[i+(1<<(j-1))]=min(f[i+(1<<(j-1))],f[i]+l);
break;
}
}
}
}
printf("%.6f\n",f[(1<<n)-1]);
}
return 0;
}
JZOJ8月10日提高组T2 Fix的更多相关文章
- 【NOIP2015模拟11.5】JZOJ8月5日提高组T2 Lucas的数列
[NOIP2015模拟11.5]JZOJ8月5日提高组T2 Lucas的数列 题目 PS:\(n*n*T*T<=10^{18}\)而不是\(10^1*8\) 题解 题意: 给出\(n\)个元素的 ...
- JZOJ8月10日提高组反思
JZOJ8月10日提高组反思 T1 没想到怎么打 就去打暴力了 本来想拿个30不错了 结果\(AC\)了 话说回来,数据也挺小的 T2 不AC便爆0 就一个数据点 给不给打暴力的人活了 正解是状压DP ...
- 【NOIP2015模拟11.2晚】JZOJ8月4日提高组T2 我的天
[NOIP2015模拟11.2晚]JZOJ8月4日提高组T2 我的天 题目 很久很以前,有一个古老的村庄--xiba村,村子里生活着n+1个村民,但由于历届村长恐怖而且黑暗的魔法统治下,村民们各自过着 ...
- JZOJ8月15日提高组反思——2020年暑假终结篇
JZOJ8月15日提高组反思--2020年暑假终结篇 T1 仙人掌最短路 抱歉我只会最短路 仙人掌是啥? 听说是缩点+\(LCA\) 最短路30 T2 直接暴力计算 正解\(DP\) \(amazin ...
- JZOJ2020年8月11日提高组T2 宝石
JZOJ2020年8月11日提高组T2 宝石 题目 Description 见上帝动了恻隐之心,天后也想显示一下慈悲之怀,随即从口袋中取出一块魔术方巾,让身边的美神维纳斯拿到后堂的屏风上去试试,屏风是 ...
- 【GDKOI2014】JZOJ2020年8月13日提高组T2 石油储备计划
[GDKOI2014]JZOJ2020年8月13日提高组T2 石油储备计划 题目 Description Input Output 对于每组数据,输出一个整数,表示达到"平衡"状态 ...
- 【五校联考1day2】JZOJ2020年8月12日提高组T2 我想大声告诉你
[五校联考1day2]JZOJ2020年8月12日提高组T2 我想大声告诉你 题目 Description 因为小Y 是知名的白富美,所以自然也有很多的追求者,这一天这些追求者打算进行一次游戏来踢出一 ...
- JZOJ8月5日提高组反思
JZOJ8月5日提高组反思 再次炸了 虽然不是爆0 但也没差多少-- T1 想的DP 然后就打了 一开始是只能拿60的 后来想到了用前缀和优化 然后打完交了 最后一分钟测了一下空间 爆了 就赶紧把数组 ...
- JZOJ8月4日提高组反思
JZOJ8月4日提高组反思 被一堆2018&2019&2020的巨佬暴打 又是愉快的爆0的一天呢 T1 看了看题 没想法 暴力走起 求个质因数呀,二分呀-- 然后就炸了 正解预处理加二 ...
随机推荐
- 解决windows下Chrome78以上跨域失效问题
1. 为什么需要解决chrome浏览器跨域的问题? 基于Hybird App的H5部分,可以直接打包进apk或者ipa包中,在开发过程中也不需要放置到临时搭建的服务器上,直接在本地打开html静态页面 ...
- C++变量的存储类型
C++变量和函数包括两个属性:数据类型和数据的存储类型.存储类型是指数据在内存中存储的方式.变量的存储类型分为四种:自动类型(auto),寄存器类型(register).静态类型(static)外部类 ...
- HTML5+CSS3 QQ会员页面导航
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- Java—字符流
一.字符流 字符流概述: 在操作过程中字节流可以操作所有数据,操作的文件中有中文字符,并且需要对 中文字符做出处理 二.字符编码表 文字-->(数字):编码."abc".ge ...
- Vuex原理详解
一.Vuex是什么 Vuex是专门为Vuejs应用程序设计的状态管理工具.它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生改变.它集中于MVC模式中的Model层 ...
- gdb 符号表 &信息 &工具
查看二进制文件的编译器版本 strings info.o |grep GCCGCC: (crosstool-NG linaro-1.13.1-2012.02-20120222 - Linaro GC ...
- 链路层输出 -qdisc
二层发送中,实现qdisc的主要函数是__dev_xmit_skb和net_tx_action,本篇将分析qdisc实现的原理,仅对框架进行分析. 其框架如下图所示 qdisc初始化 pktsched ...
- 8.java设计模式之装饰者模式
基本需求: 咖啡的种类有很多种,调料也有很多种,下单时,可以点单品咖啡也可以点单品咖啡+调料的组合,并计算下单时花费的金额 传统方式: 方式一 创建一个抽象类Drink,让所有的单品咖啡和组合咖啡都继 ...
- Luogu Daily & Original Blog (reproduced)
震惊,新的功能:可以按Ctrl + F 进行关键字查询. \(update\) on 10.26:把这两个月的日报也加入进去了,并且修复了几个错误. 本文会把小编用过的博客和比较好的博客放在这里. 可 ...
- 2020年SpringCloud 必知的18道面试题
今天跟大家分享下SpringCloud常见面试题的知识. 1.什么是Spring Cloud? Spring cloud流应用程序启动器是基于Spring Boot的Spring集成应用程序,提供与外 ...