File tree Expand file tree Collapse file tree 4 files changed +151
-0
lines changed
Expand file tree Collapse file tree 4 files changed +151
-0
lines changed Original file line number Diff line number Diff line change 1+ package CampusRecruitment2019 ;
2+
3+ import java .util .Scanner ;
4+
5+ // 迷路的牛牛
6+ public class Main004 {
7+ public static void main (String [] args ) {
8+ Scanner sc = new Scanner (System .in );
9+ int n = sc .nextInt ();
10+ String str = sc .next ();
11+
12+ // 方向抵消
13+ int res = 0 ;
14+ for (int i = 0 ; i < n ; i ++) {
15+ if (str .charAt (i ) == 'L' )
16+ res --;
17+ else
18+ res ++;
19+ }
20+ // 取余判断最后方向
21+ res %= 4 ;
22+ if (res == 0 )
23+ System .out .println ('N' );
24+ else if (Math .abs (res ) == 2 )
25+ System .out .println ('S' );
26+ else if (res == 1 || res == -3 )
27+ System .out .println ('E' );
28+ else
29+ System .out .println ('W' );
30+ }
31+ }
Original file line number Diff line number Diff line change 1+ package CampusRecruitment2019 ;
2+
3+ import java .util .Comparator ;
4+ import java .util .Scanner ;
5+ import java .util .Arrays ;
6+
7+ // 牛牛的闹钟
8+ public class Main007 {
9+ public static void main (String [] args ) {
10+ Scanner sc = new Scanner (System .in );
11+ int N = sc .nextInt ();
12+ int [][] clock = new int [N ][2 ];
13+ for (int i = 0 ; i < N ; i ++) {
14+ clock [i ][0 ] = sc .nextInt ();
15+ clock [i ][1 ] = sc .nextInt ();
16+ }
17+ int X = sc .nextInt ();
18+ int A = sc .nextInt ();
19+ int B = sc .nextInt ();
20+
21+ // 对闹钟时间排序
22+ Arrays .sort (clock , new Comparator <int []>() {
23+ @ Override
24+ public int compare (int [] o1 , int [] o2 ) {
25+ // 时钟不同则按照时钟升序排序
26+ if (o1 [0 ] != o2 [0 ])
27+ return o1 [0 ] - o2 [0 ];
28+ // 时钟相同则按照分钟升序排序
29+ return o1 [1 ] - o2 [1 ];
30+ }
31+ });
32+
33+ // 获取能及时到达教室的最晚起床时间
34+ int latest = A * 60 + B - X ;
35+ int current ;
36+ int i = 0 ;
37+ while (i < N ) {
38+ current = clock [i ][0 ] * 60 + clock [i ][1 ];
39+ // 当前闹钟时间与最晚起床时间比较,小于等于则继续判断下一个闹钟时间
40+ if (current <= latest )
41+ i ++;
42+ else
43+ break ;
44+ }
45+ System .out .print (clock [i - 1 ][0 ] + " " + clock [i - 1 ][1 ]);
46+ }
47+ }
Original file line number Diff line number Diff line change 1+ package CampusRecruitment2019 ;
2+
3+ import java .util .Scanner ;
4+ import java .util .Arrays ;
5+
6+ // 俄罗斯方块
7+ public class Main009 {
8+ public static void main (String [] args ) {
9+ Scanner sc = new Scanner (System .in );
10+ int n = sc .nextInt ();
11+ int m = sc .nextInt ();
12+ int [] count = new int [n ];
13+ int [] locat = new int [m ];
14+ for (int i = 0 ; i < m ; i ++)
15+ locat [i ] = sc .nextInt ();
16+
17+ // 统计每列的方块数,最低一列即为所获分数
18+ for (int i = 0 ; i < m ; i ++)
19+ count [locat [i ] - 1 ]++;
20+ int res = Arrays .stream (count ).min ().getAsInt ();
21+ System .out .println (res );
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ package CampusRecruitment2019 ;
2+
3+ import java .util .ArrayList ;
4+ import java .util .Arrays ;
5+ import java .util .Comparator ;
6+ import java .util .Scanner ;
7+
8+ // 塔
9+ public class Main014 {
10+ public static void main (String [] args ) {
11+ Scanner sc = new Scanner (System .in );
12+ int n = sc .nextInt ();
13+ int k = sc .nextInt ();
14+ int [][] tower = new int [n ][2 ];
15+ for (int i = 0 ; i < n ; i ++) {
16+ tower [i ][0 ] = i + 1 ; // 记录初始位置
17+ tower [i ][1 ] = sc .nextInt (); // 记录高度
18+ }
19+
20+ // 按照高度升序排序
21+ Arrays .sort (tower , Comparator .comparingInt (o -> o [1 ]));
22+
23+ // 计算余数,可知总体平均后高度差是0还是1
24+ int sum = 0 ;
25+ for (int i = 0 ; i < n ; i ++)
26+ sum += tower [i ][1 ];
27+ int rest = sum % n ;
28+
29+ ArrayList <String > list = new ArrayList <>();
30+ // 最高减最低差大于0,且有剩余操作次数
31+ while (tower [n - 1 ][1 ] - tower [0 ][1 ] > 0 && k > 0 ) {
32+ // 余数大于0且高度差为1,说明总体已经最优
33+ if (rest > 0 && tower [n - 1 ][1 ] - tower [0 ][1 ] == 1 ) break ;
34+ // 最高塔往最低塔移动立方块
35+ tower [0 ][1 ]++;
36+ tower [n - 1 ][1 ]--;
37+ k --;
38+ // 记录初始相对位置的移动操作
39+ list .add (tower [n - 1 ][0 ] + " " + tower [0 ][0 ]);
40+ // 一次操作后数组重新升序排序
41+ Arrays .sort (tower , Comparator .comparingInt (o -> o [1 ]));
42+ }
43+
44+ int min = tower [0 ][1 ], max = tower [n - 1 ][1 ];
45+ int delta = max - min ;
46+ System .out .println (delta + " " + list .size ());
47+ for (String str : list )
48+ System .out .println (str );
49+ }
50+ }
You can’t perform that action at this time.
0 commit comments