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 ...
随机推荐
- Linux 使用打印机
前言 在 deepin 上打印机好使,在我的mint上不好使,简单的查看一下deepin上驱动及软件.安装上就行了. 软件及驱动 ii hpijs-ppds 3.18.12+dfsg0-2 all H ...
- 长度最小子数组-LeetCode209 滑动窗口
力扣:https://leetcode.cn/problems/minimum-size-subarray-sum/ 题目 给定一个含有 n 个正整数的数组和一个正整数 target .找出该数组中满 ...
- MyBatis03:连接池及事务控制、xml动态SQL语句、多表操作
今日内容: mybatis中的连接池.事务控制[原理了解,应用会用] mybatis中连接池的使用及分析 mybatis中事务控制的分析 mybatis中基于xml配置的动态SQL语句使用[会用即可] ...
- 常用内置模块os sys json
今日内容回顾 目录 今日内容回顾 os模块 sys模块 json模块 json模块实战 os模块 sys模块 json模块 os模块 os模块主要与代码运行的操作系统打交道 1.创建目录(文件夹) i ...
- JavaScript:对象:如何读取、添加、删除对象的属性?
如何给对象添加属性? 直接对象名.属性名去添加属性 直接对象名[属性名]去添加属性,此时属性名得是字符串类型,可以直接引号,也可以用变量名 如何读取对象的属性值? 这个操作,和添加属性是一样的,即用点 ...
- 解决scapy库下找不到IP,TCP模板的问题
scapy版本: 问题描述: 我看到书中导入TCP,IP模块是通过from scapy.all import TCP,IP 上机实验发现找不到这个模块,通过大量查找发现此模块在最新版本中转移到其他包里 ...
- [MySQL] 索引的使用、SQL语句优化策略
目录 索引 什么是索引 索引的创建与删除 创建索引 删除索引 索引的使用 使用explain分析SQL语句 最佳左前缀 索引覆盖 避免对索引列进行额外运算 SQL语句优化 小表驱动大表 索引 什么是索 ...
- Hadoop详解(05) – MapReduce
Hadoop详解(05) – MapReduce MapReduce概述 定义 MapReduce是一个分布式运算程序的编程框架,是用户 "基于Hadoop的数据分析应用" 开发的 ...
- python之路45 初识django框架
纯手撸web框架 1.web框架的本质 理解1:连接前端与数据库的中间介质 理解2:socket服务端 2.手写web框架 1.编写socket服务端代码 2.浏览器访问响应无效>>> ...
- 【AI编译器原理】系列来啦!我们要从入门到放弃!
随着深度学习的应用场景的不断泛化,深度学习计算任务也需要部署在不同的计算设备和硬件架构上:同时,实际部署或训练场景对性能往往也有着更为激进的要求,例如针对硬件特点定制计算代码. 这些需求在通用的AI框 ...