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. Linux Shell 程序调试

    Linux Shell 程序调试 Shell程序的调试是通过运行程序时加入相关调试选项或在脚本程序中加入相关语句,让shell程序在执行过程中显示出一些可供参考的“调试信息”.当然,用户也可以在she ...

  2. 【BZOJ】1576 [Usaco2009 Jan]安全路经Travel

    [算法]最短路树+(树链剖分+线段树)||最短路树+并查集 [题解] 两种方法的思想是一样的,首先题目限制了最短路树唯一. 那么建出最短路树后,就是询问对于每个点断掉父边后重新找路径的最小值,其它路径 ...

  3. Hie with the Pie(POJ3311+floyd+状压dp+TSP问题dp解法)

    题目链接:http://poj.org/problem?id=3311 题目: 题意:n个城市,每两个城市间都存在距离,问你恰好经过所有城市一遍,最后回到起点(0)的最短距离. 思路:我们首先用flo ...

  4. 2017ACM暑期多校联合训练 - Team 2 1003 HDU 6047 Maximum Sequence (线段树)

    题目链接 Problem Description Steph is extremely obsessed with "sequence problems" that are usu ...

  5. Linux实用命令之xdg-open

    为什么要介绍 xdg-open 呢,得先从需求说起. 一般在控制台中,可以使用命令操作各式文本文件.但难以避免,需要操作一些非文本文件,如 pdf,doc 等. 此时,一般的做法是,打开文件管理器,再 ...

  6. spring boot注解学习记

    @Component Compent等效于xml文件中的Bean标注,Autowired自动初始化Bean是通过查找Component注解实现的,在增加Component后还是Autowired找不到 ...

  7. spring(四)之基于注解(Annotation-based)的配置.md

    注解 这里讲的注解有下面几个 @Autowired @Qualifier(" ") @Genre(" ") @Offline @Resource(name=&q ...

  8. Codeforces Round #423 Div. 2 C-String Reconstruction(思维)

    题目大意:告诉你n个字符串以及这些字符串在字符串s中出现的位置(x1,x2.....xn),要求在满足上述条件的情况下,求出字典序最小的字符串s. 解题思路:主要问题是,如果直接模拟是会超时的,比如v ...

  9. Tornado入门资料整理

    预备知识 没学过计网的苦逼找点现成一些的东西看吧…… <Restful Web Services>,<HTTP The Definitive Guide>,各种RFC WSGI ...

  10. centos使用boost过程

    1. 安装gcc,g++,make等开发环境 yum groupinstall "Development Tools" 2. 安装boost  yum install boost ...