【Codeforces 1106C】Lunar New Year and Number Division
【链接】 我是链接,点我呀:)
【题意】
题意
【题解】
看了下样例解释就懂了。。。
每次选择最大最小的两个组合 然后加起来。。
【代码】
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
static int n;
static int a[];
static long sqr(long x) {
return x*x;
}
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
n = in.nextInt();
a = new int[n+10];
for (int i = 1;i <= n;i++) a[i] = in.nextInt();
Arrays.sort(a, 1,n+1);
int l = 1,r = n;
long ans = 0;
while (l<=r) {
ans = ans + sqr(a[l]+a[r]);
l++;r--;
}
System.out.println(ans);
}
}
【Codeforces 1106C】Lunar New Year and Number Division的更多相关文章
- 【Codeforces 1106E】Lunar New Year and Red Envelopes
[链接] 我是链接,点我呀:) [题意] 给你k个红包,每个红包可以在si..ti的时间范围内拿走. 抢完红包之后你得到wi元,然后你需要在di+1时刻才能继续抢红包 时间是线性的从1..n 然后某个 ...
- 【Codeforces 1106D】Lunar New Year and a Wander
[链接] 我是链接,点我呀:) [题意] 让你遍历n个节点,访问过的节点不操作. 如果是没有访问过的点,那就把它加到序列的末尾. 问你形成的最小字典序的序列是多少. [题解] 显然每次找最小的标号 用 ...
- 【Codeforces 1106B】Lunar New Year and Food Ordering
[链接] 我是链接,点我呀:) [题意] 给你n个菜以及每个人需要的菜以及数量 如果某个人无法满足它对菜的需求的话 就用价格比较低的菜来填充它的要求. (如果价格低的菜不够了,那么就直接输出0) 否则 ...
- 【Codeforces 1106E】 Lunar New Year and Red Envelopes
Codeforces 1106 E 题意:有\(k\)个红包,第\(i\)个红包可以在\(s_i\)到\(t_i\)的时间内抢,同时获得\(w_i\)的钱,但是抢完以后一直到\(d_i\)都不可以继续 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
随机推荐
- JavaScript Patterns 2.6 switch Pattern
Principle • Aligning each case with switch(an exception to the curly braces indentation rule). • Ind ...
- (多项式)因式分解定理(Factor theorem)与多项式剩余定理(Polynomial remainder theorem)(多项式长除法)
(多项式的)因式分解定理(factor theorem)是多项式剩余定理的特殊情况,也就是余项为 0 的情形. 0. 多项式长除法(Polynomial long division) Polynomi ...
- bzoj 2069 [ POI 2004 ] ZAW —— 多起点最短路 + 二进制划分
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2069 首先,对于和 1 相连的点,一定是从某个点出发,回到另一个点: 所以需要枚举起点和终点 ...
- 必会!Linux文件的管理
1.1 创建一个目录 /data [root@liuhao ~]# mkdir /data 1.2 查看目录是否创建成功 <可以找到data即为创建成功> [root@liuhao ~]# ...
- Rails 拉数据初始数据库
rails c [1] pry(main)> Scraping.exec
- [App Store Connect帮助]二、 添加、编辑和删除用户(3)添加和编辑用户
您可以在“用户和访问”中添加和编辑用户. 如果您以个人名义在“Apple 开发者计划”注册,您可以授权用户访问您 App Store Connect 中的内容.所有用户只拥有 App Store Co ...
- [Swift通天遁地]九、拔剑吧-(9)创建支持缩放、移动、裁切的相机视图控制器
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- applicationContext.xml配置AOP切面编程
Computer.java package com.wh.aop2; public class Computer { public void play01(){ System.out.println( ...
- [ BZOJ 4318 & 3450 / CodeForces 235 B ] OSU!
\(\\\) \(Description\) 一共进行\(N\)次操作,生成一个长度为\(N\)的\(01\)序列,成功对应\(1\),失败对应\(0\),已知每一次操作的成功率\(p_i\). 在这 ...
- Spring的核心机制依赖注入
原文地址:http://developer.51cto.com/art/200610/33311.htm 本文主要讲解依赖注入(设值注入.构造注入),作用是可以使Spring将各层的对象以松耦合的方式 ...