暴力!暴力!之”Unfair Poll”

本文探讨了一个复杂的点名算法,该算法在大型班级中以特定模式进行学生提问,旨在找出在大量提问后,被提问次数最多和最少的学生,以及特定学生的被提问次数。文章提供了详细的解题思路,并附带了AC代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目:

On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others.

Seating in the class looks like a rectangle, where n rows with m pupils in each.

The teacher asks pupils in the following order: at first, she asks all pupils from the first row in the order of their seating, then she continues to ask pupils from the next row. If the teacher asked the last row, then the direction of the poll changes, it means that she asks the previous row. The order of asking the rows looks as follows: the 1-st row, the 2-nd row, ..., the n - 1-st row, the n-th row, the n - 1-st row, ..., the 2-nd row, the 1-st row, the 2-nd row, ...

The order of asking of pupils on the same row is always the same: the 1-st pupil, the 2-nd pupil, ..., the m-th pupil.

During the lesson the teacher managed to ask exactly k questions from pupils in order described above. Sergei seats on the x-th row, on the y-th place in the row. Sergei decided to prove to the teacher that pupils are asked irregularly, help him count three values:

  1. the maximum number of questions a particular pupil is asked,
  2. the minimum number of questions a particular pupil is asked,
  3. how many times the teacher asked Sergei.

If there is only one row in the class, then the teacher always asks children from this row.

Input

The first and the only line contains five integers n, m, k, x and y (1 ≤ n, m ≤ 100, 1 ≤ k ≤ 1018, 1 ≤ x ≤ n, 1 ≤ y ≤ m).

Output

Print three integers:

  1. the maximum number of questions a particular pupil is asked,
  2. the minimum number of questions a particular pupil is asked,
  3. how many times the teacher asked Sergei.
Example Input

1 3 8 1 1

4 2 9 4 2

5 5 25 4 3

100 100 1000000000000000000 100 100

Example Output

3 2 3

2 1 1

1 1 1

101010101010101 50505050505051 50505050505051

Note

The order of asking pupils in the first test:

  1. the pupil from the first row who seats at the first table, it means it is Sergei;
  2. the pupil from the first row who seats at the second table;
  3. the pupil from the first row who seats at the third table;
  4. the pupil from the first row who seats at the first table, it means it is Sergei;
  5. the pupil from the first row who seats at the second table;
  6. the pupil from the first row who seats at the third table;
  7. the pupil from the first row who seats at the first table, it means it is Sergei;
  8. the pupil from the first row who seats at the second table;

The order of asking pupils in the second test:

  1. the pupil from the first row who seats at the first table;
  2. the pupil from the first row who seats at the second table;
  3. the pupil from the second row who seats at the first table;
  4. the pupil from the second row who seats at the second table;
  5. the pupil from the third row who seats at the first table;
  6. the pupil from the third row who seats at the second table;
  7. the pupil from the fourth row who seats at the first table;
  8. the pupil from the fourth row who seats at the second table, it means it is Sergei;
  9. the pupil from the third row who seats at the first table;


题目大意:有一个倒霉的班级,有一种有毒的点名方式,如图:

在横向总是1,2,3...n;在纵向总是1,2,3...n-1,n,n-1,n-2...2,1,2...;

有个倒霉孩子在这个班级的(x,y)上。

问你,在点了k次名字的情况下被点到次数最多和最少的次数分别是多少,这个倒霉孩子又被点了几次。

解题思路:因为k相当大,因此要对其进行优化,我们会发现一次循环是 两倍的m*n再减去两倍的m,即2*m*n - 2*m;

对其取余后在暴力涂色求解就可以了,因为教室最大仅仅有10000,一次循环不过不到20000;

AC代码:

 

 1 import java.util.*;
 2 
 3 public class H{
 4     public static void main(String[] args){
 5         Scanner sc = new Scanner(System.in);
 6         while(sc.hasNext()){
 7             long n = sc.nextLong();
 8             long m = sc.nextLong();
 9             long k = sc.nextLong();
10             long x = sc.nextLong();
11             long y = sc.nextLong();
12             if(n == 1){
13                 long max = 0;long min = 0;long ser = 0;
14                 if(k % m == 0){max = k / m;min = k / m;ser = k / m;}
15                 else {max = k / m + 1;min = k / m;
16                     if(k % m >= y){ser = k / m + 1;}
17                     else{ser = k / m;}
18                 }
19                 System.out.println(max + " " + min + " " + ser);
20             }
21             else if(n > 1){
22                 long max = -1;long min = 10000000000000000L;
23                 long round = 2*m*n - 2*m;
24                 long sum_r = k / round;
25                 long left = k % round;
26                 long print[][] = new long[101][101];
27                 for(int i = 1;i <= (int)n;i ++){//先涂整数圈
28                     for(int j = 1;j <= (int)m;j ++){
29                         if(i == (int)1 || i == (int)n){print[i][j] = sum_r;}
30                         else if(i < n && i > 1){print[i][j] = sum_r * 2;}
31                     }
32                 }
33                 //涂剩下的余数
34                 for(int i = 1;i <= (int)n;i ++){//正着涂 1 -- n
35                     for(int j = 1;j <= (int)m;j ++){
36                         if(left > 0){print[i][j] ++;left --;}
37                     }
38                 }
39                 for(int i = (int)(n - 1);i >= 2;i --){//反着涂 n-1 -- 2
40                     for(int j = 1;j <= (int)m;j ++){
41                         if(left > 0){print[i][j] ++;left --;}
42                     }
43                 }
44                 //再暴力求最大最小
45                 for(int i = 1;i <= (int)n;i ++){
46                     for(int j = 1;j <= (int)m;j ++){
47                         if(max < print[i][j]){max = print[i][j];}
48                         if(min > print[i][j]){min = print[i][j];}
49                     }
50                 }
51                 System.out.println(max + " " + min + " " + print[(int)x][(int)y]);
52             }
53         }
54     }
55 }

 

 

转载于:https://www.cnblogs.com/love-fromAtoZ/p/7245193.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值