360第二题 最后没提交啊,不知道对不对,求哪位大神看看

import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
int[] arr = new int[T];
for (int i = 0; i < T; i++) {
int[] tm = new int[3];
tm[0] = sc.nextInt();
tm[1] = sc.nextInt();
tm[2] = sc.nextInt();
Arrays.sort(tm);
while (tm[2]>=2 && tm[1]>=1) {
tm[2] -= 2;
tm[1] -= 1;
arr[i]++;
Arrays.sort(tm);
}
if (tm[0]==1 && tm[1]==1 && tm[2]==1) {
arr[i]++;
}
}
sc.close();
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
}

#实习##笔试题目#
全部评论
感觉这么做会超时,我第一个方法是这样做的然后40超时
点赞 回复 分享
发布于 2018-03-31 21:42
会超时的,因为我也是这样……
点赞 回复 分享
发布于 2018-03-31 21:46
超时,不用看。。。。
点赞 回复 分享
发布于 2018-03-31 21:53
三个数先比较出大中小。如果大>中*2+小*2,结果是中+小,否则结果是(大+中+小)/3
点赞 回复 分享
发布于 2018-03-31 21:57

相关推荐

02-15 22:29
门头沟学院 Java
点赞 评论 收藏
分享
2024-12-26 13:00
太原理工大学 Java
会飞的猿:简历没啥大问题啊,感觉是缺少了实习经历。多投投先找个中小厂过渡一下吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务