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 vlc设置中文问题
解决方法 sudo apt install vlc-l10n
- 【每日一题】【DFS】2022年1月5日-543. 二叉树的直径
给定一棵二叉树,你需要计算它的直径长度.一棵二叉树的直径长度是任意两个结点路径长度中的最大值.这条路径可能穿过也可能不穿过根结点. 答案: /** * Definition for a binary ...
- MySQL的select for update用法
MySQL中的select for update大家应该都有所接触,但什么时候该去使用,以及有哪些需要注意的地方会有很多不清楚的地方,我把我如何使用和查询到的文档在此记录. 作用 select本身是一 ...
- gulp4.0构建任务
执行default任务时,依次执行以下任务 gulp.task('default', ['htmlmin', 'cssmin', 'jsmin', 'copy']); 报错:Task function ...
- RocketMQ Schema——让消息成为流动的结构化数据
本文作者:许奕斌,阿里云智能高级研发工程师. Why we need schema RocketMQ 目前对于消息体没有任何数据格式的约束,可以是 JSON ,可以是对象 toString ,也可以只 ...
- uniapp微信小程序 下拉刷新(上拉请求下一页数据)
<template>标签中: <view class="" v-if="daShow==1"> <view class=" ...
- python 集合常用操作
集合的特性 无序.不重复.可迭代 常用api 创建一个集合 需要显式地使用set()方法来声明,如果使用字面量{}来声明解析器会认为这是一个字典. add() 往集合中添加一个元素 demo = se ...
- 2、Java封装、继承与多态
/** * 类.对象.面向过程.面向对象的理解: * 1.类:类是封装对象的属性和方法的载体 * * 2.对象:对象是类抽象出来的一个实例 * * 3.面向过程:面向过程注重的是具体的实现过程,因果关 ...
- python实验报告(第11章)
实验11:使用Python操作数据库 一.实验目的和要求 1.学会数据库编程接口: 2.学会使用SQLite: 3.学会使用MySQL. 二.实验环境 软件版本:Python 3.10 64_bit ...
- Codeforces Hello 2023 CF 1779 A~F 题解
点我看题 A. Hall of Fame 先把不用操作就合法的情况判掉.然后发现交换LL,RR,RL都是没用的,只有交换LR是有用的,这样可以照亮相邻的两个位置.所以我们就是要找到一个位置i,满足\( ...