2711: [Violet 2]After 17

Time Limit: 5 Sec  Memory Limit: 128 MB
Submit: 224  Solved: 153

Description

Input

Output

Sample Input

4
4 5
1 2
3 3
4 1

Sample Output

-38.00

HINT

Source

【分析】

  虽然是道水题,但是我今天终于自己真正想出来一道了,撒花~~还挤到第7啦~~

  点积的话,就是求$x2*x1+x3*x1+x3*x2+...+xn*x(n-1)+y2*y1+y3*y1+y3*y2+...yn*y(n-1)$

  设$sumx=x1+x2+...+xn, sumy=y1+y2+...yn$

  就是$sumx^2-\sum xi^2+sumy^2-\sum yi^2$

  $x$和$y$没有半毛钱关系,分开做。

  其实是很显然$(x,y)$是只会选择那角落四个点的【这是套路也是可以证(luan)明(shuo)的,【就是假设把一个$x$增加$a$ 贡献是$2a(x-sumx)$,你总往好的一边增加就好了。

  那么$xi^2+yi^2$也是固定的。

  那么就要$sumx$和$sumy$尽量接近0就好了。

  这个,很熟悉吧?把$\dfrac{\sum xi}{2}$当成背包容量,把背包尽量填满就行了,这个0-1背包bool就好。

 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define Maxn 210
#define LL long long bool f[Maxn*Maxn];
int nx[Maxn],ny[Maxn]; int main()
{
int n,ans=,h1=,h2=;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
ans-=x*x+y*y;
h1+=x;h2+=y;
nx[i]=x;ny[i]=y;
}
memset(f,,sizeof(f));
f[]=;
for(int i=;i<=n;i++)
{
for(int j=h1/;j>=nx[i];j--)
{
f[j]|=f[j-nx[i]];
}
}
int mx=;
for(int i=;i<=h1/;i++) if(f[i]) mx=i;
ans+=(h1-*mx)*(h1-*mx);
memset(f,,sizeof(f));
f[]=;
for(int i=;i<=n;i++)
{
for(int j=h2/;j>=ny[i];j--)
{
f[j]|=f[j-ny[i]];
}
}
mx=;
for(int i=;i<=h2/;i++) if(f[i]) mx=i;
ans+=(h2-*mx)*(h2-*mx);
printf("%.2lf\n",ans*1.0/);
return ;
}

2017-04-06 16:45:10

【BZOJ 2711】 2711: [Violet 2]After 17 (0-1 背包)的更多相关文章

  1. CentOS 6.5安装Erlang/OTP 17.0

    CentOS 6.5安装Erlang/OTP 17.0 作者:chszs,转载需注明.博客主页:http://blog.csdn.net/chszs Erlang眼下已经是Fedora和Debian/ ...

  2. centos 7 运行Quartus ii 17.0 标准版,下载程序时遇到错误error (209053): unexpected error in jtag server -- error code 89

    对于错误error (209053): unexpected error in jtag server -- error code 89,它产生的原因在于,在linux系统下,Quartus ii的驱 ...

  3. Altium Designer (17.0) 打印输出指定的层

    Altium Designer (17.0) 例如,打印输出Top Overlay,Keep-Out Layer 1.先选择PCB文件,在单击按键Print Preview... 2.在预览区单击鼠标 ...

  4. openwrt从18.0.1降级回到17.0.6遇到的问题

    因为觉得openwrt的18的配置检查功能很费时,特别是遇到ar93xx慢的真可以,所以决定从18.0.1降回到17.0.6上 先把18.0.1的配置backup出来,然后刷17.0.6,再把back ...

  5. This Android SDK requires Android Developer Toolkit version 17.0.0 or above. Current version is 10.0.0.v201102162101-104271. Please update ADT to the latest version.

    win7/xp 下面安装Android虚拟机,更新SDK后,在Eclipse preference里指向android-sdk-windows时. 出现 : This Android SDK requ ...

  6. Docker 在转发端口时的这个错误Error starting userland proxy: mkdir /port/tcp:0.0.0.0:3306:tcp:172.17.0.2:3306: input/output error.

    from:https://www.v2ex.com/amp/t/463719 系统环境是 Windows 10 Pro,Docker 版本 18.03.1-ce,电脑开机之后第一次运行 docker ...

  7. PIG之 Hadoop 2.7.4 + pig-0.17.0 安装

    首先: 参考 http://blog.csdn.net/zhang123456456/article/details/77621487 搭建好hadoop集群. 然后,在master节点安装pig. ...

  8. iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 8001 -j DNAT --to-destination 172.17.0.5:8080 ! -i docker0: iptables: No chain/target/match by that name.

    在docker容器上部署项目后,启动docker容器,出现 iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dpor ...

  9. 修复升级ndk到17.0.4754217编译so失败问题

    今天编译工程总过不去,查看失败原因,因为ndk的mips编译不过去. A problem occurred starting process ‘command ‘/Users/didi/Library ...

随机推荐

  1. Fast File System

    不扯淡了,直接来写吧,一天一共要写三篇博客,还有两篇呢. 1. 这篇博客讲什么? Fast File System(FFS)快速文件系统,基本思想已经在在上一篇博客File System Implem ...

  2. CentOS部署.NetCore服务

    1. 安装CentOs,可使用最小安装包镜像:http://isoredirect.centos.org/centos/7/isos/x86_64/CentOS-7-x86_64-Minimal-17 ...

  3. LintCode 402: Continuous Subarray Sum

    LintCode 402: Continuous Subarray Sum 题目描述 给定一个整数数组,请找出一个连续子数组,使得该子数组的和最大.输出答案时,请分别返回第一个数字和最后一个数字的下标 ...

  4. 【CodeForces】899 F. Letters Removing

    [题目]F. Letters Removing [题意]给定只含小写字母.大写字母和数字的字符串,每次给定一个范围要求删除[l,r]内的字符c(l和r具体位置随删除变动),求m次操作后的字符串.n&l ...

  5. 使用Docker 快速搭建nuget本地服务器,Hosting private nuget server using docker in seconds!

    Server #below line automatically creates the folder, mount the volumes and maps the ports. docker ru ...

  6. 探讨一个“无法创建JVM”的问题(已解决)

    ava版本:1.4 运行设置: -Xms1G -Xmx4G 报错: [ Incompatible initial and maximum heap sizes specified: ][ initia ...

  7. 机器学习-kNN(1)

    一 kNN算法简介 kNN(K-Nearest Neighbor)工作原理:存在一个样本数据集合,也称为训练样本集,并且样本集中每个数据都存在标签,即我们知道样本集中每一数据与所属分类对应的关系.输入 ...

  8. (转)USB体系结构

    转载地址:http://blog.ednchina.com/zenhuateng/203584/Message.aspx USB总线接口层:物理连接.电气信号环境.信息包传输机制:主机一方由USB主控 ...

  9. Centos 6.4搭建git服务器【转】

    前阵子公司需要,让我搭个Git服务器,把之前用的SVN上代码迁移到git上去,所以就在阿里云主机上搭了一个,记录了下安装过程,留存文档以备查阅.本篇本章只涉及搭建部分的操作,更多git的使用可以参考文 ...

  10. 136.Single Number---异或、位运算

    题目链接 题目大意:给出一串数组,里面的数都是两个,只有一个数是一个,把这个只有一个的数找出来.时间复杂度最好是线性的,空间复杂度最好为O(1). 法一:利用map,空间换时间,代码如下(耗时26ms ...