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 看到这样的设问我们可以很自然地联想到这道题,具体来说我们可以通过某种方式建出一张图,然后根据" ...
随机推荐
- JSON, list, 前台显示
前台 $(function(){ $.getJSON("/portal/visitor/getVisitorCount?rn="+Math.random(),function(js ...
- Anaroid WebView详解大全
资源描述: 1.android提供了webView控件专门用来浏览网页.然后在程序中装载webView控件,设置属性,比如:颜色.字体.要访问的网址等.通过loadUrl方法设置当前webView需要 ...
- openCV(四)---Canny边缘检测
图像的边缘检测的原理是检测出图像中所有灰度值变化较大的点,而且这些点连接起来就构成了若干线条,这些线条就可以称为图像的边缘. 直接上代码,函数简介都在代码注释中 //canny边缘检测 -(void) ...
- kafuka常用的shell命令
kafka常用shell命令: ------------------------------------ 1.创建topic bin/kafka-topics.sh --create --zookee ...
- JS-如何把字符串转换成数组
var a = "1,22,33,44"; // 字符串 var b = a.split(","); // 将字符串按照","分割,存入数组 ...
- 非常简单的oracle和mysql数据互传
工具是navicat,我用的是Navicat Premium 10: 这个工具可以同时连接mysql和oracle,如图: 同时连接上这两个库之后 工具->数据传输 左边是数据源,右边是导入目标 ...
- java 类与对象
class XiyoujiRenwu { float height,weight; String head, ear; void speak(String s) { System.out.printl ...
- Linux学习 -- Shell编程 -- 条件判断
按照文件类型进行判断 两种格式 test -e /root/install.log [ -e /root/install.log ] 注意空格 适合用于脚本中 echo $?可以看到结果 [ - ...
- ubuntu 12.04 安装snort acidbase相关注意事项
一.安装Snort 1.安装libpcap 1 apt-get install libpcap-dev 2.安装snort 1 2 apt-get install snort apt-get inst ...
- PAT (Advanced Level) 1112. Stucked Keyboard (20)
找出一定没问题的字符(即一连串的额字符x个数能被k整除的),剩下的字符都是可能有问题的. #include<cstdio> #include<cstring> #include ...