CodeForces 76E Points
给出n个点,求任意两点间距离的平方和。
暴力显然超时,可以把公式写出来,化简一下,发现预处理一下后缀和就可以o(n)出解了。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std; const int maxn=+;
struct Point
{
long long x,y;
}p[maxn];
int n;
long long sum[maxn];
long long a[maxn]; long long get(int x)
{
long long res=;
int tot=;
if(x==) for(int i=;i<=n;i++) a[i]=p[i].x;
else for(int i=;i<=n;i++) a[i]=p[i].y;
sum[n+]=; for(int i=n;i>=;i--) sum[i]=sum[i+]+a[i];
for(int i=;i<=n;i++) res=res+a[i]*a[i]*(n-);
for(int i=;i<=n-;i++) res=res-*a[i]*sum[i+];
return res;
} int main()
{
scanf("%d",&n);
long long ans=;
for(int i=;i<=n;i++) scanf("%lld%lld",&p[i].x,&p[i].y);
ans=ans+get();
ans=ans+get();
printf("%lld\n",ans);
return ;
}
CodeForces 76E Points的更多相关文章
- codeforces 872E. Points, Lines and Ready-made Titles
http://codeforces.com/contest/872/problem/E E. Points, Lines and Ready-made Titles time limit per te ...
- codeforces 251A Points on Line(二分or单调队列)
Description Little Petya likes points a lot. Recently his mom has presented him n points lying on th ...
- CodeForces 19D Points
Pete and Bob invented a new interesting game. Bob takes a sheet of paper and locates a Cartesian coo ...
- CodeForces 19D Points (线段树+set)
D. Points time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- CodeForces 577E Points on Plane(莫队思维题)
题目描述 On a plane are nn points ( x_{i}xi , y_{i}yi ) with integer coordinates between 00 and 10^{6} ...
- 『ACM C++』 Codeforces | 1066A - Points in Segments
大一生活真 特么 ”丰富多彩“ ,多彩到我要忙到哭泣,身为班长,很多班级的事情需要管理,也是,什么东西都得体验学一学,从学生会主席.团委团总支.社团社长都体验过一番了,现在差个班长也没试过,就来体验了 ...
- Codeforces 870E Points, Lines and Ready-made Titles:并查集【两个属性二选一】
题目链接:http://codeforces.com/problemset/problem/870/E 题意: 给出平面坐标系上的n个点. 对于每个点,你可以画一条经过这个点的横线或竖线或什么都不画. ...
- CodeForces 19D Points(离散化+线段树+单点更新)
题目链接: huangjing 题意:给了三种操作 1:add(x,y)将这个点增加二维坐标系 2:remove(x,y)将这个点从二维坐标系移除. 3:find(x,y)就是找到在(x,y)右上方的 ...
- Codeforces 429E - Points and Segments(欧拉回路)
Codeforces 题面传送门 & 洛谷题面传送门 果然我不具备融会贯通的能力/ll 看到这样的设问我们可以很自然地联想到这道题,具体来说我们可以通过某种方式建出一张图,然后根据" ...
随机推荐
- java使用iText生成pdf表格
转载地址:http://www.open-open.com/code/view/1424011530749 首先需要你自己下载itext相关的jar包并添加引用,或者在maven中添加如下引用配置: ...
- [转]php 在各种web服务器的运行模式
一.php在apache中运行模式 php在apache中一共有三种工作方式:CGI模式.FastCGI模式.Apache 模块DLL) 以下分别比较: 1. CGI模式与模块模式比较: php在ap ...
- Flex4.6 DataGrid GridItemRenderer宣染器
本文转自:http://blog.sina.com.cn/s/blog_71848dcf01012ctl.html,稍作修改 <?xml version="1.0" enco ...
- ASP之Eval、Execute、ExecuteGlobal区别分析
Eval.Execute.ExecuteGlobal 这三个语句(函数)都是执行字符串表达式,不过它们之间又有所不同. Eval 计算一个表达式的值并返回结果. 语法:[result = ]eval( ...
- zf-分页后台代码
java : public ResultPage getDeptList(int page, int pageRows) throws Exception { String hql="fro ...
- 1.1 mysql安装
直接百度mysql 即可下载.. 下载完毕之后是压缩包,解压缩即可 解压之后可以将该文件夹改名,放到合适的位置,个人建议把文件夹改名为MySQL Server 5.6,放到D:\MySQL Serve ...
- mysql 不能插入中文
三.#vim /etc/mysql/my.cnf .(5.5以前系统)在[client]下面加入 default-character-set=utf8 在[mysqld]下面加入default-cha ...
- Spring Boot 系列教程15-页面国际化
internationalization(i18n) 国际化(internationalization)是设计和制造容易适应不同区域要求的产品的一种方式. 它要求从产品中抽离所有地域语言,国家/地区和 ...
- Dynamic Performance Tables not accessible Automatic Statistics disabled for this session
使用oracle时候统计会出现这个提示 Dynamic Performance Tables not accessible Automatic Statistics disabled for this ...
- hdu 1180诡异的楼梯(bfs)
诡异的楼梯 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Total Submis ...