[结论] LibreOJ #520. 「LibreOJ β Round #3」绯色 IOI(开端)
来源:互联网 发布:linux中压缩文件命令 编辑:程序博客网 时间:2024/05/10 10:55
题意
戳这里
题解
这是一道结论题。
我们先把数放到数轴上考虑。定义两个点的距离为几何上的距离的平方。
我们可以把一个回路看作两条从
有一种经典的二路取数的
怎么办呢?只能观察性质了,这里有一个很强的结论:
除了最两端的
证明如下:
显然有
知道这个结论就是傻逼题了。
直接连边:
#include<cstdio>#include<algorithm>using namespace std;const int maxn=100005;typedef long long LL;int n,a[maxn];LL ans;LL sqr(LL x){ return x*x; }int main(){ scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+1+n); ans+=sqr(a[1]-a[2])+sqr(a[n-1]-a[n]); for(int i=1;i<=n-2;i++) ans+=sqr(a[i]-a[i+2]); printf("%lld\n",ans); return 0;}
阅读全文
0 0
- [结论] LibreOJ #520. 「LibreOJ β Round #3」绯色 IOI(开端)
- #520. 「LibreOJ β Round #3」绯色 IOI(开端) 贪心
- [匹配+拓扑] LibreOJ #521. 「LibreOJ β Round #3」绯色 IOI(抵达)
- LibreOJ β Round #3
- LibreOJ #505.「LibreOJ β Round」ZQC 的游戏 网络流
- LibreOJ #504. 「LibreOJ β Round」ZQC 的手办 线段树+堆
- [数学杂题] LibreOJ #530「LibreOJ β Round #5」最小倍数
- [数学杂题] LibreOJ#532. 「LibreOJ β Round #5」随机数列
- 「LibreOJ β Round #2」DP 一般看规律
- loj#526. 「LibreOJ β Round #4」子集
- [LibreOJ β Round #4]游戏
- [LibreOJ β Round #4]多项式
- [LibreOJ β Round #4]子集
- [LibreOJ β Round #4]框架
- [LibreOJ β Round #4]求和
- LibreOj
- #507. 「LibreOJ NOI Round #1」接竹竿 dp
- 「LibreOJ β Round #2」贪心只能过样例 [bitset]【STL】
- JS正则表达式
- flume与kafka
- Redis主从同步分析
- SQL distinct去重并排序失败
- C#(4)-------处理/Date(1502326189000)/格式数据
- [结论] LibreOJ #520. 「LibreOJ β Round #3」绯色 IOI(开端)
- Bash Shell环境
- SpringMvc之参数绑定注解详解
- 设计模式之对象行为型模式 — COMMAND (命令)模式
- maven学习笔记(四) 使用maven命令创建项目
- [SDUT](2143)图结构练习——最短路径 ---单源最短路径(图)
- LeetCode 633. Sum of Square Numbers
- tf之object detect摄像头物体识别测试
- echo 改变输出文本颜色