美团内推2018编程题1——改考卷

来源:互联网 发布:江苏移动网络怎么样 编辑:程序博客网 时间:2024/05/15 05:00

学生分为n组,每个组si个人,老师收取第一组所有试卷,发给第二组同学,同时收取第二组同学的试卷放在手中试卷的底下.........一直到收取最后一组试卷,再将手中试卷发给第一组学生。

这样存在两个问题:1,手中试卷不够发给下一组同学的;2,有的同学改自己的试卷

这两个问题与老师收取试卷的顺序有一定关系,你能否设计老师收取试卷的顺序从而避免上述两个问题,若存在一定顺序,输出“Yes”,否则,输出“No”。


输入:

第一行:分组个数

第二行:每个组的学生数

输出:

能满足条件:Yes

不能满足条件:No


输入样例:

2

20 10

4

1 3 2 3

输出样例:

No

Yes

tips:样例2的顺序为3 3 1 2 时就可以避免这两个问题。


import java.util.*;public class Main{public static void main(String[] args){    Scanner in = new Scanner(System.in);    int n = in.nextInt();            int[] a = new int[n];                        for(int i = 0; i < n; i++){            a[i] = in.nextInt();            }                        Arrays.sort(a);                        if(n == 2 && a[0] == a[1])            System.out.println("Yes");            else if((n == 2 && a[0] != a[1]) || n == 1)            System.out.println("No");                        else {                int temp = 0 ;                for(int i =0; i < n-1; i++){                temp += a[i];                }                                if(temp < a[n-1]){                System.out.println("No");                }else{                System.out.println("Yes");                }                        }    }}


阅读全文
0 0
原创粉丝点击