Unfair Poll codeforce758 C

来源:互联网 发布:淘宝凤凰体育 编辑:程序博客网 时间:2024/05/21 03:27
传送门

题目:
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, wheren 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, the2-nd row,..., then - 1-st row, then-th row, then - 1-st row,..., the2-nd row, the1-st row, the2-nd row,...

The order of asking of pupils on the same row is always the same: the1-st pupil, the2-nd pupil,..., them-th pupil.

During the lesson the teacher managed to ask exactlyk questions from pupils in order described above. Sergei seats on thex-th row, on they-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 integersn,m,k,x andy (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、3、 ... n、n-1、n-2、... 2、1,对列的提问顺序为从 1 到 m ,求解被提问次数最多的学生,被提问次数最少的学生,坐在(x, y)座位上的学生,各被提问了多少次。
思路:
      从 1、2、...n、n-1、...2 是一个周期,(2n-2)*m次。每次循环第 1 行和第 n 行都只有一次,其他行为两次,当行数为1 或 2 时单独讨论。

代码:15ms
#include<stdio.h>#include<algorithm>#include<string.h>#include<string>#include<iostream>#include<math.h>using namespace std;#define LL long longLL n, m, k, x, y;int main(){    cin>>n>>m>>k>>x>>y;    LL p, r, masum, misum, ans;    if(n == 1)    {        p = k/m;  r = k%m;        masum = k/m + (r > 0);        misum = k/m;        ans = p + (r >= y);    }    else    {        if(k <= m*n)        {            masum = 1;            misum = (k == m*n ? 1 : 0);            ans = ((x-1)*m + y <= k);        }        else        {            p = k/(m*n+(n-2)*m);            r = k % (m*n+(n-2)*m);            if(n == 2)                masum = p + (r >= 1);            else                masum = 2*p + (r > m) + (r > m*n);            misum = p + (r >= m*n);            if(x == 1 || x == n)                ans = p + (r >= (x-1)*m + y);            else            ans = 2*p + (r >= (x-1)*m + y) + (r >= n*m+(n-x-1)*m + y);        }    }    cout<<masum<<" "<<misum<<" "<<ans<<endl;    return 0;}

如有错误,欢迎指出~

                
原创粉丝点击