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

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

2017-01-21 14:57 459 查看
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;

题目大意:

给你一个N*M的班级座位排布的矩形。老师提问都是按照1.2.3.4..........n.n-1.n-2.........1.2.3..................的行顺序来提问的。每一行的提问顺序都是1.2.3.4.......m不变。

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

思路:可以发现其实有个周期的,就是从1-n,再从n-1到2,一共n-2行可以作为一个周期,这一点我想到了,其实剩下就是很简单了,for暴力模拟剩下的点名。。。然而我这个智障还想直接用数据算出来。。。好菜啊啊,,,,

贴一个我自己一开始写的代码:

其实想通过计算直接算出来。。。我这种算法是不对的,因为每一行都是从1-m,如果后面的是从m-1就对了。。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
ll n, m, k, x, y;
cin >> n >> m >> k >> x >> y;
ll min1, max1, J;
if(n == 1)
{
min1 = k / m;
if(k%m) max1 = k / m + 1;
else max1 = min1;
if(k%m < x) J = min1;
else J = max1;
cout << max1 << ' ' << min1 << ' ' << J << endl;
return 0;
}
if(n == 2)
{
ll c = 2*m;
ll cnt = (x-1)*m + y;
min1 = k / c;
if(k%c) max1 = min1 + 1;
else max1 = min1;
if(k%c < cnt) J = min1;
else J = max1;
cout << max1 << ' ' << min1 << ' ' << J << endl;
return 0;
}
ll c = (n*2-2) * m;
ll cnt1 = (x-1)*m + y;
ll cnt2 = (n*m-cnt1) * 2 - m + cnt1 + 1;
ll t = k / c;
min1 = k / c;
if(k%c > n*m) max1 = t*2 + 2, min1++;
else if(k%c <= n*m && k%c != 0)
{
if(k%c == n*m)
min1++;
max1 = t*2+1;
}
else if(k%c == 0) max1 = t*2;
if(x == 1 || x == n)
{
if(k%c < cnt1)
J = t;
else
J = t + 1;
}
else
{
if(k%c < cnt1)
J = t*2;
else if(k%c < cnt2)
J = t*2 + 1;
else if(k%c >= cnt2)
J = t*2 + 2;
cout<< k%c << ' ' << cnt1 << ' ' << cnt2 << endl;
}
// cout << max1 << ' ' << min1 << ' ' << J << endl;
return 0;
}


正解:
其实想到了周期就特别简单了。。。谨记,cf暴力出奇迹。。不必想太多。。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
const int maxn = 105;
const ll INF = 1e18;
ll cnt[maxn*2][maxn];
int main()
{
ll n, m, k, x, y, mi = INF, mx = -INF, c;
cin >> n >> m >> k >> x >> y;
if(n == 1) //特判下1的时候,这时候周期为0
{
ll J;
mi = k / m;
if(k%m) mx = k / m + 1;
else mx = mi;
if(k%m < y) J = mi;
else J = mx;
cout << mx << ' ' << mi << ' ' << J << endl;
return 0;
}
c = k / ((2*n-2)*m);
k %= ((2*n-2)*m); //余数
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
cnt[i][j] += c; //模拟点名
for(int i = n - 1; i >= 2; i--)
for(int j = 1; j <= m; j++)
cnt[i][j] += c;
for(int i = 1; i <= n && k; i++) //模拟点名,剩下的看能点到哪里
for(int j = 1; j <= m && k; j++)
cnt[i][j]++, k--;
for(int i = n - 1; i >= 2 && k; i--) //注意max跟min千万不能放到这个里面,因为这里面有个k,很容易就跳出去了,然后后面的数据看不到了,要在下面重新写一个for来找mx跟mi
for(int j = 1; j <= m && k; j++)
cnt[i][j]++, k--;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
mi = min(mi, cnt[i][j]), mx = max(mx, cnt[i][j]);
cout << mx << ' ' << mi << ' ' << cnt[x][y] << endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: