组队竞赛

组队竞赛

http://www.nowcoder.com/questionTerminal/248ccf8b479c49a98790db17251e39bb

以下两种方式都可以 注意核心思想一定是先从小到大培排序 取第一个 和最后2个 组合成一组 取中间数
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n= scanner.nextInt();
List<integer> resultList = new ArrayList<>();
while (scanner.hasNext()){
resultList.add(scanner.nextInt());
}
Collections.sort(resultList);
long result = 0;
for (int i=0;i< n ;i++){
result +=resultList.get(3n -2(i+1));
}
System.out.println(result);
}</integer>

public static void test1() {
Scanner scanner = new Scanner(System.in);
int n;
long[] data;
while(scanner.hasNext()){
n=scanner.nextInt();
data = new long[3n];
for (int i = 0; i <data.length ; i++) {
data[i] = scanner.nextLong();
}
Arrays.sort(data);
long result = 0;
for (int i = 0; i < n; i++) {
result+=data[data.length-(2
(i+1))];
}
System.out.println(result);
}

}
全部评论

相关推荐

奔跑的suechil...:怎么评论区这么多打广告的 1.项目考虑是两个,可以加个项目 2.bg一般的话,不建议外卖加点评,99%都过不了简历 3.找项目要么是自己找github好点的开源,要么是评论区找广告去跟着,要么就是星球找项目了 加油友友
点赞 评论 收藏
分享
01-04 14:19
已编辑
重庆科技大学 Java
想和你交朋友的秋田犬...:唉 现在acm已经没那么吃香了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务