【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个) 问你最少走多远; [题解] 肯定不多走啊; ...
随机推荐
- Bing Maps进阶系列二:使用GeocodeService进行地理位置检索
Bing Maps进阶系列二:使用GeocodeService进行地理位置检索 在<Bing Maps进阶系列一:初识Bing Maps地图服务>里已经对GeocodeService的功能 ...
- Java 数组的 12 个方法
1. 声明一个数组 String[] aArray = new String[5]; String[] bArray = {"a","b","c&q ...
- Spark SQL读parquet文件及保存
import org.apache.spark.{SparkConf, SparkContext} import org.apache.spark.sql.{Row, SparkSession} im ...
- 腾讯云SSL证书管理
2018050608010400y5mbx15awnpwxfhdmd7zqet1i9dzaqkvb6lxzosi4qq5ezbr
- form表单点击后验证
function check(){ var customertype = document.getElementById("customertype"); //alert(cust ...
- 关于DOM操作的相关案例
1.模态框案例 需求: 打开网页时有一个普通的按钮,点击当前按钮显示一个背景图,中心并弹出一个弹出框,点击X的时候会关闭当前的模态框 代码如下: <!DOCTYPE html> <h ...
- MVC系列学习(八)-分布视图
1.本次学习实例 1.1.建议:为了尽可能让项目简单,就新建一个空的mvc项目,同时添加任何视图不用模板页 1.2注意:在添加LoginPart的分部视图时,要记得沟一个沟 2.项目代码,如下 总共三 ...
- JVM 垃圾回收器详解
小结: 新生代 串行Serial 并行 Parallel(关注吞吐量) 并行ParNew 老年代 串行 Serial Old 并行Para ...
- 【转】Java 集合系列08之 List总结(LinkedList, ArrayList等使用场景和性能分析)
概要 前面,我们学完了List的全部内容(ArrayList, LinkedList, Vector, Stack). Java 集合系列03之 ArrayList详细介绍(源码解析)和使用示例 Ja ...
- window.showModalDialog的问题
通过window.showModalDialog的方式弹出B页面,总报“拒绝访问”的错误,将站点添加到受信任站点可以解决这个问题