[刷题]Codeforces 758C

来源:互联网 发布:价格歧视 知乎 编辑:程序博客网 时间:2024/06/05 07:22

Description

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

input1 3 8 1 1output3 2 3input4 2 9 4 2output2 1 1input5 5 25 4 3output1 1 1input100 100 1000000000000000000 100 100output101010101010101 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;

Key

如此简单的题目竟然当时没做出来,心态爆炸。死在了边界和自作聪明上。
每个人从0开始编号,即0~m-1,以便于取模运算等。以提问第1,2,3,.....,n1,n,n1,...4,3,2排的所有人为一轮,提问次数记为round,计算出除了最后一轮外一共的轮数rounds以及最后一轮被提问的最后一个人的位置。
若n=1或者n=2,单独考虑,此时相当于每一个人在每一轮里只被问了一遍。否则:

  1. 当最后一个人在第一排,则最小值为rounds,最大值为max(rounds+1,2*rounds),讨论Sergei有没有在最后一轮被提问且Sergei是不是第一排或最后一排的;
  2. 当最后一个人在第一排与最后一排之间且是第一次被提问,则最小值为rounds,最大值为2*rounds+1,讨论Sergei有没有在最后一轮被提问且Sergei是不是第一排或最后一排的;
  3. 当最后一个人在最后一排且不是最后一排最后一个人,则最小值为rounds,最大值为2*rounds+1,一样的还是要讨论Sergei情况;
  4. 当最后一个人在最后一排最后一个人时,则最小值为rounds+1,最大值为2*rounds+1,一样的还是要讨论Sergei情况;
  5. 当最后一个人在从后向前提问顺序(即第二次被提问)时,则最小值为rounds+1,最大值为2*rounds+2,一样的还是要讨论Sergei情况;

所以可能性还是稍微有点复杂的,尤其是讨论Sergei在不在第一排或最后一排的问题上。我还吃力不讨好地在一两种情况上面把完全不耗时间的(x == 1 || x == n) ? :优化成(x == 1) ? :(x == n) ? :,结果就优化出问题了。你说我何必呢。。。

最气的是,网上看到的题解都是模拟。。。二维数组一开,美滋滋。。。心态崩了。

Code

#include<iostream>#include<algorithm>using namespace std;typedef long long LL;LL n, m, k, x, y;LL maxn, minn, midn;int main(){    ios::sync_with_stdio(false);    cin >> n >> m >> k >> x >> y;    --k;    LL round = (n == 1 ? m : (2 * n - 2)*m);    LL rounds = k / round;    LL last = k % round;    if (n < 3) {        maxn = rounds + 1;        minn = ((last == round - 1) ? rounds + 1 : rounds);        midn = ((x - 1)*m + y - 1 > last ? minn : maxn);    }    else {        maxn = rounds * 2;        minn = rounds;        if (last < m) {            maxn = max(rounds * 2, rounds + 1);            if ((x - 1)*m + y - 1 > last) midn = ((x == 1 || x == n) ? rounds : rounds * 2);            else midn = rounds + 1;        }        else if (last < m*(n - 1)) {            ++maxn;            if ((x - 1)*m + y - 1 > last) midn = ((x == n) ? rounds : rounds * 2);            else midn = ((x == 1) ? rounds + 1 : rounds * 2 + 1);        }        else if (last < m*n) {            ++maxn;            if (last == m*n - 1)++minn;            if ((x - 1)*m + y - 1 > last) midn = rounds;            else midn = ((x == 1 || x == n) ? rounds + 1 : rounds * 2 + 1);        }        else {            maxn += 2;            ++minn;            if (n*m + (n - x - 1)*m + y - 1 > last) midn = ((x == 1 || x == n) ? rounds + 1 : rounds * 2 + 1);            else midn = ((x == 1 || x == n) ? rounds + 1 : rounds * 2 + 2);        }    }    cout << maxn << ' ' << minn << ' ' << midn;    return 0;}
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 新开的网店没生意怎么办 淘小二介入买家举证不全怎么办 新股申购中签后钱不够怎么办 买的东西收不到怎么办? 拼多多按错收货怎么办 团购招生做到一半不如意怎么办 网购付款后卖家没有货怎么办 淘宝退货商家不同意退款怎么办 淘宝确认收货后卖家拒绝退款怎么办 淘宝卖家不同意退款怎么办 淘宝仅退款卖家不处理怎么办 淘宝申请退款卖家不处理怎么办 快递没收到货要退款怎么办 发票给了不给钱怎么办 付款后不给发票怎么办 供货商不给发票怎么办 刚生过孩子太胖买衣服怎么办 黑色牛仔裤洗的发白怎么办 蘑菇街手机丢了怎么办 黑衣服上全是白毛毛怎么办 支付宝注销了钱怎么办 网上买东西手机号写错了怎么办 二类工资卡过万怎么办 淘宝发货地址写错怎么办 淘宝发货地址写错了怎么办 淘宝不能代付了怎么办 支付宝付款码被盗刷怎么办 地方选举追究不到相关责任人怎么办 天正建筑画个直线找不到怎么办 Wi-Fi模块不支持多播怎么办? 魅族手机屏幕点不动怎么办 uc打开网页很慢怎么办 京东手机号码无法登录怎么办 织梦系统网站没收录怎么办 电脑开机出现一堆乱码怎么办 电脑文件夹出现乱码打不开怎么办 电脑出现f1和f2怎么办 电脑中韩文内容显示乱码怎么办 入驻shopee没身份证怎么办 液相色谱柱柱压降低怎么办 c18色谱柱堵了怎么办