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 看到这样的设问我们可以很自然地联想到这道题,具体来说我们可以通过某种方式建出一张图,然后根据" ...
随机推荐
- 关于微信分享功能开发的一些bug
wx.onMenuShareTimeline({//onMenuShareTimeline title: (h('#mainForm').children('.content').inf('value ...
- javascript克隆一个对象
/* * 克隆一个对象 */ com.ty.repairtech.JsonOperation.clone = function(obj) { // Handle the 3 simple types, ...
- Chrome不支持showModalDialog模态对话框和无法返回returnValue的问题
父窗体部分js代码: var returnValue = window.showModalDialog("son.html ", window); //for chrome if ...
- User.java 实体类 带 数据库字段模板
package com.tgb.web.controller.entity; import javax.persistence.Column; import javax.persistence.Ent ...
- jquery滚动条加载数据
//滚动条 $(window).scroll(function () { var scrollTop = $(this).scrollTop(); var scrollHeight = $( ...
- asp.net无法触发asp控件的后台方法
前台代码: <asp:Button ID="btnFinish" runat="server" Text="完成" Font-Size ...
- qmake pro工程设置
----我的生活,我的点点滴滴!! #以下是在terminal里面编译,想编译哪个就修改pro文件 #================================================= ...
- Oracle10 多行和并
SELECT fspc, wmsys.wm_concat (jsrzmc) as jsr FROM dxjsrxx GROUP BY fspc select fspc, LISTAGG(jsrzmc, ...
- Drivers Dissatisfaction
Drivers Dissatisfaction time limit per test 4 seconds memory limit per test 256 megabytes input stan ...
- HDU2586 How far away ? 邻接表+DFS
题目大意:n个房子,m次询问.接下来给出n-1行数据,每行数据有u,v,w三个数,代表u到v的距离为w(双向),值得注意的是所修建的道路不会经过一座房子超过一次.m次询问,每次询问给出u,v求u,v之 ...