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 看到这样的设问我们可以很自然地联想到这道题,具体来说我们可以通过某种方式建出一张图,然后根据" ...
随机推荐
- iOS中date和string的相互转换
必须知道的内容 G: 公元时代,例如AD公元 yy: 年的后2位 yyyy: 完整年 MM: 月,显示为1-12 MMM: 月,显示为英文月份简写,如 Jan ...
- laravel使用多个数据库连接
1.配置.env文件 DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=database_name DB_USERNAME= ...
- 把perl脚本编译成exe
来源:http://www.veryhuo.com/a/view/38338.html 今天想把 perl 脚本编译成 exe 以便脱离 perl 解释器独立运行.都可以生成PERL的PE文件,在PE ...
- Inno Setup入门(四)——为程序创建桌面快捷方式
Icons这一可选段定义所有创建在开始菜单和\或其它位置 (比如桌面) 的快捷方式.一个例子如下: [setup] ;全局设置,本段必须 AppName=Test AppVerName=TEST De ...
- Object调用控件的办法
<OBJECT id="pwdpad" style="LEFT: 0px; WIDTH: 35px; TOP: 0px; HEIGHT: 16px" cl ...
- offset,client,scroll,style相关笔记
1.offsetTop 功能:获取元素上外缘与最近的定位父元素内壁的距离,如果没有定位父元素,则是与文档上内壁的距离 使用方法:js document.querySelector(...).offse ...
- SEO策略与细节:细节决定成败
昨天展开seo探讨会.听了一场医疗界seo大神的讲座.收益匪浅今天讲他的演讲内容整理出来与大家分享.希望对医疗界的seo带来些帮助.站长们一起成长! 一.首页 1.元标签设置 标题:上海癫痫病医院哪家 ...
- POJ 1308/并查集
题目链接 /* 判断一棵树: * 1.There is exactly one node, called the root, to which no directed edges point. * 2 ...
- Core Data & MagicalRecord
iOS 本地数据持久化存储: 1.plist 2.归档 3.NSUserDefaults 4.NSFileManager 5.数据库 一.CoreData概述 CoreData是苹果自带的管理数据库的 ...
- MySql数据库基本介绍和基本语法
一.数据库简单介绍 1. 按照数据库的发展时间顺序,主要出现了以下类型数据库系统: Ø 网状型数据库 Ø 层次型数据库 Ø 关系型数据库 Ø 面向对象数据库 上面4中数据库系统中,关系型数据库使用最为 ...