codeforces 758C - Unfair Poll 细节题

本文解析了一道关于教室中教师提问模式的算法题。该题要求找出提问次数最多和最少的学生,并计算特定学生的被提问次数。通过巧妙设计的循环节处理方法,实现了高效求解。

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

C. Unfair Poll
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 withm 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: the1-st row, the 2-nd row,..., the n - 1-st row, then-th row, the n - 1-st row,..., the 2-nd row, the1-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 thex-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.
Examples
Input
1 3 8 1 1
Output
3 2 3
Input
4 2 9 4 2
Output
2 1 1
Input
5 5 25 4 3
Output
1 1 1
Input
100 100 1000000000000000000 100 100
Output
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;
题目大意:有n行m列学生,有一位老师在课上会问k个问题,在行上,是按照1,2。。。。n-1,n,n-1.。。。1这样的顺序提问,列操作上总是从第1列到第m列,对于每个输入询问,回答问题最多的学生回答了几次,最少的回答了几次,(x,y)位置上的同学回答了几次。

题解:很明显这是一道模拟题,但是看到数据范围,我们肯定不能O(n)的模拟,所以我们先处理循环节,这是本题重点。一个循环节是从第1排一直到返回第一排(第一排只计算一次),对循环节取余数。对余数可以进行逐个模拟最多不超过20000次,可以接受。

代码如下
#include <iostream>
#include <bits/stdc++.h>

using namespace std;

long long a[105][105];

int main()
{
    long long n,m,k,x,y;
    cin>>n>>m>>k>>x>>y;
    long long lh=0;
    for(int i=0;i<n;i++)
        lh+=m;
    for(int i=n-2;i>0;i--)
        lh+=m;
    for(int i=1;i<n-1;i++)
        for(int j=0;j<m;j++)
        a[i][j]+=2*(k/lh);
    for(int i=0;i<m;i++)
        a[0][i]+=k/lh;
    if(n!=1)
    {
        for(int i=0;i<m;i++)
            a[n-1][i]+=k/lh;
    }
    k%=lh;
    if(k!=0)
    {
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++)
            {
                a[i][j]++;
                k--;
                if(k==0)
                    break;
            }
            if(k==0)
                break;
        }
        if(k!=0)
        {
            for(int i=n-2;i>0;i--){
                for(int j=0;j<m;j++)
                {
                    a[i][j]++;
                    k--;
                    if(k==0)
                        break;
                }
                if(k==0)
                    break;
            }
        }
    }
    long long max1=0,min1=1e18+1;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
        {
            //cout<<a[i][j]<<endl;
            max1=max(a[i][j],max1);
            min1=min(a[i][j],min1);
        }
    cout<<max1<<' '<<min1<<' '<<a[x-1][y-1]<<endl;
    return 0;
}


 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值