您的位置:首页 > 大数据 > 人工智能

Codeforces 758C-   Unfair Poll

2017-09-17 09:37 906 查看
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 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:

the maximum number of questions a particular pupil is asked,
the minimum number of questions a particular pupil is asked,
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:

the maximum number of questions a particular pupil is asked,
the minimum number of questions a particular pupil is asked,
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:

the pupil from the first row who seats at the first table, it means it is Sergei;
the pupil from the first row who seats at the second table;
the pupil from the first row who seats at the third table;
the pupil from the first row who seats at the first table, it means it is Sergei;
the pupil from the first row who seats at the second table;
the pupil from the first row who seats at the third table;
the pupil from the first row who seats at the first table, it means it is Sergei;
the pupil from the first row who seats at the second table;

The order of asking pupils in the second test:

the pupil from the first row who seats at the first table;
the pupil from the first row who seats at the second table;
the pupil from the second row who seats at the first table;
the pupil from the second row who seats at the second table;
the pupil from the third row who seats at the first table;
the pupil from the third row who seats at the second table;
the pupil from the fourth row who seats at the first table;
the pupil from the fourth row who seats at the second table, it means it is Sergei;
the pupil from the third row who seats at the first table;

题目大意:有n行m列学生,有一位老师在课上会问k个问题,在行上,是按照1,2。。。。n-1,n,n-1.。。。1这样的顺序提问,求学生当中回答问题个数最多和最少的个数,以及在第x行第y位的同学回答的问题数。


要学习别人的代码.

#include<bits/stdc++.h>

using namespace std;

#define LL long long
#define MP(a,b) make_pair(a,b)
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=a;i<=b;++i)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define pii pair<int,int>
#define sf scanf
#define pf printf

const int maxn = 100;

int n, m, xx, yy;
LL kk, mmp[maxn+5][maxn+5];

int main()
{
sf("%d%d%lld%d%d", &n, &m, &kk, &xx, &yy);
LL a, b, c, ans1, ans2, ans3;
int type;
if(n == 1)
{
ans1 = ans2 = kk/m, b = kk%m;
if(b) ++ans1;
ans3 = (yy<=b) ? ans1 : ans2;
pf("%lld %lld %lld\n", ans1, ans2, ans3);
return 0;
}
a = (n-1)*m*2;
b = kk/a, c = kk%a;
mem(mmp, 0);
REP(i,1,n-1) REP(k,1,m)//这个学
mmp[i][k] += b;//都直接放到这里面就不怕了.不会犯特例的错
REP(i,2,n) REP(k,1,m)
mmp[i][k] += b;
int ti = 1, tk = 1;
while(ti<n && c)
{
++mmp[ti][tk], ++tk, --c;
if(tk==m+1) ++ti, tk = 1;
}
while(ti>=1 && c)
{
++mmp[ti][tk], ++tk, --c;
if(tk==m+1) --ti, tk = 1;
}
LL mx = 0, mm = 1e18;
REP(i,1,n) REP(k,1,m)
{
mx = max(mx, mmp[i][k]);
mm = min(mm, mmp[i][k]);
}
pf("%lld %lld %lld\n", mx, mm, mmp[xx][yy]);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: