当前位置: 代码迷 >> 综合 >> Codeforces Round #392 (Div. 2) 758C Unfair Poll 【模拟】
  详细解决方案

Codeforces Round #392 (Div. 2) 758C Unfair Poll 【模拟】

热度:54   发布时间:2023-11-11 10:58:13.0

题目传送门:点击打开链接

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,3.。。。。。n,n-1,n-2,n-3.......1

每一排都是从1号开始到m号结束。  问按照这样的问法。回答问题最多的同学回答了几题?最少的回答了几题?小明在第x行第y列,小明回答了几题?


我们可以按照这个顺序画出几个周期。我们不难发现,一个周期为:1,2,3,4,。。。。n,n-1,n-2,...,2 

在这个周期中。第一排和第n排都只问了一次。

按照这个规律我们用一个二维数组模拟教室的座位。每个元素的值代表这个位置的同学回答的问题数目。最后扫一遍就行了


#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define M(a)  memset(a,0,sizeof(a))
LL num[105][105];///记录每个座位的题目数
int main()
{LL k;LL n,m,x,y;while(~scanf("%lld %lld %lld %lld %lld",&n,&m,&k,&x,&y)){M(num);if(n==1)///只有一排时单独分为一个情况{LL temp=k%m;///temp代表周期以外的剩余部分LL temp2=(k-temp)/m;for(int i=1; i<=m; i++){if(temp>0){temp--;num[1][i]++;}num[1][i]+=temp2;}LL MIN=num[1][1];LL MAX=num[1][1];for(int i=1; i<=m; i++)///得出最大值和最小值{if(num[1][i]<=MIN){MIN=num[1][i];}if(num[1][i]>=MAX){MAX=num[1][i];}}printf("%lld %lld %lld\n",MAX,MIN,num[x][y]);}else{LL temp=k%(2*n*m-2*m);LL temp2=(k-temp)/(2*n*m-2*m);for(int i=1; i<=n; i++){for(int j=1; j<=m; j++){if(i==1||i==n){num[i][j]=temp2;///第一行和第n行在一个周期里只回答了一次}else{num[i][j]=temp2*2;///其他行都是两次}}}while(temp>0)///处理周期以外的部分{for(int i=1; i<=n&&temp>0; i++){if(i==n){for(int c=n; c>=2&&temp>0; c--){for(int l=1; l<=m&&temp>0; l++){temp--;num[c][l]++;}}}else{for(int j=1; j<=m&&temp>0; j++){temp--;num[i][j]++;}}}}//            for(int i=1; i<=n; i++)
//            {
//                for(int j=1; j<=m; j++)
//                {
//                    printf("%d ",num[i][j]);
//                }
//                printf("\n");
//            }LL MAX=num[1][1];LL MIN=num[1][1];for(int i=1; i<=n; i++){for(int j=1; j<=m; j++){if(num[i][j]<=MIN){MIN=num[i][j];}if(num[i][j]>=MAX){MAX=num[i][j];}}}printf("%lld %lld %lld\n",MAX,MIN,num[x][y]);}}return 0;
}


  相关解决方案