JZOJ 1121. Fix
解析
考场时想多了,其实根本不用分阶段
一维状压 \(DP\) 就行了
可我没想清楚,加了个第几次去稳固一个点的阶段
然后时间就炸了!!!
\(Code\)
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
double f[1 << 19] , ans;
int n;
struct points{
int x , y , z;
}a[20];
struct node{
double a;
int b;
}d[20][20];
inline bool cmp(node x , node y){return x.a < y.a;}
inline double calc(points x , points y){
return sqrt(((double)x.x - y.x) * (x.x - y.x) + ((double)x.y - y.y) * (x.y - y.y));
}
inline double min(double x , double y){return x < y ? x : y;}
int main()
{
while (1)
{
scanf("%d" , &n);
if (n == 0) break;
for(register int i = 1; i <= n; i++) scanf("%d%d%d" , &a[i].x , &a[i].y , &a[i].z);
for(register int i = 0; i < (1 << n); i++) f[i] = (double)1e18;
for(register int i = 1; i < 1 << n; i++)
{
int bz = 1;
for(register int j = n - 1; j >= 0; j--)
if (((i >> j) & 1) && (a[j + 1].z != 1)){bz = 0; break;}
if (bz) f[i] = 0;
}
for(register int i = 1; i <= n; i++)
{
for(register int j = 1; j <= n; j++)
{
d[i][j].a = calc(a[i] , a[j]);
d[i][j].b = j;
}
sort(d[i] + 1 , d[i] + n + 1 , cmp);
}
int l = 0;
for(register int i = 1; i < 1 << n; i++)
{
int s = 0;
for(register int j = n - 1; j >= 0; j--)
if ((i >> j) & 1) s++;
if (s < 2 || f[i] == (double)1e18) continue;
for(register int j = n - 1; j >= 0; j--)
if (!((i >> j) & 1))
{
int o = 1 , oo = 2;
while (!(i & (1 << d[j + 1][o].b - 1)) && o <= n) o++;
oo = o + 1;
while (!(i & (1 << d[j + 1][oo].b - 1)) && oo <= n) oo++;
f[i | (1 << j)] = min(f[i | (1 << j)] , f[i] + d[j + 1][o].a + d[j + 1][oo].a);
}
}
ans = min((double)1e18 , f[(1 << n) - 1]);
if (ans == (double)1e18) printf("No Solution\n");
else printf("%.6lf\n" , ans);
}
}
JZOJ 1121. Fix的更多相关文章
- PhpStorm和WAMP配置调试参数,问题描述Error. Interpreter is not specified or invalid. Press “Fix” to edit your project configuration.
PhpStorm和WAMP配置调试参数 问题描述: Error. Interpreter is not specified or invalid. Press “Fix” to edit your p ...
- No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.
Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...
- Eclipse ndk fix插件开发
一. 手工修复ndk环境bug Eclipse做ndk开发的时候, 经常会遇到编译过去,却报语法错误的问题,比如 ①. 头文件不识别 ②. 头文件识别了, 类型不识别 针对这一的bug,我们一般按照如 ...
- How to Fix GNOME License Not Accepted Issue on CentOS 7
This post assume that you have just finished the Gnome GUI installation on CentOS 7 by using “yum gr ...
- Nodemanager Out of heap memory[fix bug全过程]
问题: 自己写了一个yarn上的application,发现nodemanager过段时间,会out of memory退出,把nodemanager的heap memory从1G增大到2G也是无法避 ...
- mathlab之floor,ceil,round,int以及fix函数
建议自己动手敲敲,网上很多人自己都没搞清楚然后好多错的.毕竟自己亲眼看到结果才有说服力. 以下是我亲眼见到的结果. 1.double floor(double)函数 floor()函数是常用的取整函数 ...
- 【hihoCoder】1121:二分图一·二分图判定
题目 http://hihocoder.com/problemset/problem/1121 无向图上有N个点,两两之间可以有连线,共有M条连线. 如果对所有点进行涂色(白/黑),判定是否存 ...
- matlab size、numel、length、fix函数的使用,补充nargin
size():获取矩阵的行数和列数 (1)s=size(A), 当只有一个输出参数时,返回一个行向量,该行向量的第一个元素时矩阵的行数,第二个元素是矩阵的列数.(2)[r,c]=size(A), 当有 ...
- Can't use Subversion command line client: svn Probably the path to Subversion executable is wrong. Fix it.
1.最近使用SVN工具时,Checkout出项目到本地后后,然后将其导入到Intellij idea中开发,在提交svn代码的时候,出现这样的错误:Can't use Subversion comma ...
- 自定义母版页之列表过滤菜单位置issue fix
问题描述: 自定义母版页,为了使左边导航和顶部导航位置不变(不滚动),将原本位于ribbon下方的#s4-workspace调整到左侧导航右边. <div id="s4-workspa ...
随机推荐
- JSON提取器中串联一个接口的多个值传给下个接口(compute concatenation var的实际使用场景)
实际场景:某功能在前端支持选择多条数据后点击提交,表现在接口是,一次传了多个Id. 问题:需要将上个接口的多个Id串联,传给提交接口. 处理方式:通过JSON提取器勾选:compute concate ...
- Apache Dubbo 多语言体系再添新员:首个 Rust 语言版本正式发布
Dubbo Rust 定位为 Dubbo 多语言体系的重要实现,提供高性能.易用.可扩展的 RPC 框架,同时通过接入 Dubbo Mesh 体系提供丰富的服务治理能力.本文主要为大家介绍 Dubbo ...
- Jenkins基本配置
1.Configure System (系统设置) 在系统设置这里,只需要设置最后面的一项,配置远程服务器地址,即代码最终运行的服务器地址信息,当然这里是可以配置多台远程Linux服务器的,配置完成后 ...
- redis集合 实现 队列
先说一下需求:用队列解决 流量削峰,主要应用场景:商城秒杀功能. 以下是业务流程图可以参考一下: 然后本地实现思路 截图下单页面 每次购买数量会减少1,设置了1000个库存,用户id 是随机生成的. ...
- [深度学习] imgaug边界框增强笔记
imgaug边界框增强笔记主要是讲述基于imgaug库对目标检测图像的边界框进行图像增强.本文需要掌握imgaug库的基本使用,imgaug库的基本使用见[深度学习] imgaug库使用笔记. 文章目 ...
- Vue + Element 自定义上传封面组件
前一段时间做项目,频繁使用到上传图片组件,而且只上传一个封面,于是想着自定义一个图片封面上传组件.先来看一下效果: 第一张图片是上传之前,第二张图片是上传 ...
- python之路39 前端开始 各种标签
前端前夕 前端三剑客 HTML 网页的骨架 CSS 网页的样式 JavaScript 网页的动态 1.编写服务端 2.浏览器充当客户端访问服务端 3.浏览器无法正常展示服务端内容(因为服务端得数据没用 ...
- [WPF]将方法设为弃用
[System.Obsolete("这是一条提示信息,表示这个方法弃用了,使用此方法会有一条Warning信息")] private void SaveDataMessage(Sa ...
- python利用matplotlib生成迷宫
起因 我想要写一个项目叫python迷宫游戏,需求是玩家能和机器对抗率先走出迷宫,至少要有两个等级的电脑. 慢慢来,首先迷宫游戏需要有一个迷宫并展示出来,这便是这篇博客的目的 假设迷宫使用0表示点,1 ...
- python3连接postgresql/greenpulm
python3安装:pip install psycopg2github地址:https://github.com/psycopg/psycopg2文档地址:http://initd.org/psyc ...