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 ...
随机推荐
- kettle 链接oracle12c
jdbc连接cdb数据库时,url兼容以下2种模式: "jdbc:oracle:thin:@192.168.75.131:1521:oracle12c" "jdbc:or ...
- js 获取相同name元素的属性值
如图有8-12月5个文本域,id为plan8-12,name同为plan. 现在要获取name同为plan的所有属性值: 方法一: var allplan =document.getElementsB ...
- 使用Supervisor监控mysql
Supervisor安装教程参考:https://www.cnblogs.com/brad93/p/16639953.html mysql安装教程参考:https://www.cnblogs.com/ ...
- Python编程规范之PEP8
Python编程规范-PEP8 PEP是 Python Enhancement Proposal 的缩写. 英文链接: https://legacy.python.org/dev/peps/pep-0 ...
- 网络基础与osi七层与TCP/IP协议
一 什么是网络 网络:计算机网络是一组计算机或网络设备通过有形 的线缆或无形的媒介如无线,连接起来,按照一定的 规则,进行通信的集合. 通信,是指人与人.人与物.物与物之间通过某种媒 介和行为进行的 ...
- 创建并且配置win10系统虚拟机
一.创建Windows10镜像 1.下载地址:https://www.microsoft.com/zh-cn/software-download/windows10 2.制作镜像 完成之后,会生成一个 ...
- 8个Spring事务失效的场景,你碰到过几种?
前言 作为Java开发工程师,相信大家对Spring种事务的使用并不陌生.但是你可能只是停留在基础的使用层面上,在遇到一些比较特殊的场景,事务可能没有生效,直接在生产上暴露了,这可能就会导致比较严重的 ...
- 在IQuery中使用除法提示"Numeric value does not fit in a System.Decimal"
起因 有个需求是需要汇总(单耗=单件用量*1+损耗率)的值,由于现在我们数据库中存的XX率都是放大了一百倍(即10%数据库存的是10),然后就很自然的写了个linq汇总如下 materialOrder ...
- 【爬虫+数据分析+数据可视化】python数据分析全流程《2021胡润百富榜》榜单数据!
目录 一.爬虫 1.1 爬取目标 1.2 分析页面 1.3 爬虫代码 1.4 结果数据 二.数据分析 2.1 导入库 2.2 数据概况 2.3 可视化分析 2.3.1 财富分布 2.3.2 年龄分布 ...
- Netty-架构设计及入门程序-3
一.原生 NIO 存在的问题 1.NIO 的类库和 API 繁杂,使用麻烦:需要熟练掌握 Selector.ServerSocketChannel.SocketChannel.ByteBuffer等. ...