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

Codeforces Round #392(Div. 2) C Unfair Poll【思维+暴力】

2017-01-20 14:14 323 查看
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的班级座位排布的矩形。老师提问都是按照1.2.3.4..........n.n-1.n-2.........1.2.3..................的行顺序来提问的。每一行的提问顺序都是1.2.3.4.......m不变。

让你找到被提问最多次数的学生被提问了多少次,以及被提问最少次数的学生被提问了多少次,还有固定位子(x,y)这个人被提问了多少次。

思路:

1、首先观察到N,M并不大,那么我们考虑先处理掉提问次数剩余<N*M的时候,那么剩下的部分我们只要暴力涂提问次数即可。

2、我们发现提问一轮(从1走出去再回到1)是按照1.2.3.4....n.n-1.....2来的。

那么就是第一行和最后一行只涂了一次(提问了一次);

中间的所有行都涂了两次。

那么每一轮提问都需要涂:(2*n-2)*m次。

那么我们一共就涂了K/((2*n-2)*m)个整数次。

那么剩余部分就是K%((2*n-2)*m)。

剩余部分暴力涂上去即可。

查询也是暴力查询的。

3、注意一点,N==1的时候需要特判。

Ac代码:

#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
#define ll __int64
ll ans[150][150];
ll n,m,k,x,y;
int main()
{
while(~scanf("%I64d%I64d%I64d%I64d%I64d",&n,&m,&k,&x,&y))
{
if(n==1)
{
ll all=k/(n*m);
ll yu=k%(n*m);
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m; j++)
{
if(yu>=1)
ans[i][j]=all+1;
else ans[i][j]=all;
yu--;
}
}
ll maxn=-0x3f3f3f3f;
ll minn=2000000000000000000;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m; j++)
{
maxn=max(maxn,ans[i][j]);
minn=min(minn,ans[i][j]);
}
}
printf("%I64d %I64d %I64d\n",maxn,minn,ans[x][y]);
}
else
{
ll all=k/((2*n-2)*m);
ll yu=k%((2*n-2)*m);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(i==1||i==n)ans[i][j]=all;
else ans[i][j]=all*2;
}
}
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m; j++)
{
if(yu>=1)
ans[i][j]++;
yu--;
}
}
for(int i=n-1; i>=2; i--)
{
for(int j=1; j<=m; j++)
{
if(yu>=1)
ans[i][j]++;
yu--;
}
}
ll maxn=-0x3f3f3f3f;
ll minn=2000000000000000000;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m; j++)
{
maxn=max(maxn,ans[i][j]);
minn=min(minn,ans[i][j]);
}
}
printf("%I64d %I64d %I64d\n",maxn,minn,ans[x][y]);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Codeforces#392Div. 2