[刷题]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,以便于取模运算等。以提问第
若n=1或者n=2,单独考虑,此时相当于每一个人在每一轮里只被问了一遍。否则:
- 当最后一个人在第一排,则最小值为rounds,最大值为max(rounds+1,2*rounds),讨论Sergei有没有在最后一轮被提问且Sergei是不是第一排或最后一排的;
- 当最后一个人在第一排与最后一排之间且是第一次被提问,则最小值为rounds,最大值为2*rounds+1,讨论Sergei有没有在最后一轮被提问且Sergei是不是第一排或最后一排的;
- 当最后一个人在最后一排且不是最后一排最后一个人,则最小值为rounds,最大值为2*rounds+1,一样的还是要讨论Sergei情况;
- 当最后一个人在最后一排最后一个人时,则最小值为rounds+1,最大值为2*rounds+1,一样的还是要讨论Sergei情况;
- 当最后一个人在从后向前提问顺序(即第二次被提问)时,则最小值为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;}
- [刷题]Codeforces 758C
- [刷题]Codeforces 794C
- [刷题]Codeforces 811C
- 【codeforces 758C】Unfair Poll
- codeforces-758【B、C思维】
- Codeforces 758C-Unfair Poll
- Codeforces 758C Unfair Poll
- Codeforces 758C- Unfair Poll
- Codeforces 758C Unfair Poll 暴力模拟
- codeforces 758C - Unfair Poll 细节题
- Codeforces 758C Unfair Poll 【数学】【思维】
- 【Codeforces 758 C Unfair Poll】+ 细节
- CodeForces 758C Unfair Poll(模拟)
- Codeforces-340-C(c++)
- Codeforces-507-C(c++)
- CodeForces 731C C
- CodeForces-612C C
- CODEFORCES 265C CODEFORCES, 265C
- 事务和连接池总结
- 简述 Docker
- KMP算法Next数组计算
- Spring学习之AOP
- 441. Arranging Coins
- [刷题]Codeforces 758C
- JAVA集合框架中的常用集合及其特点、适用场景、实现原理简介
- JNI开发之JNI简介
- 1110: 排列
- Ubuntu16.04--ROS--kinetic
- mybatis分页
- P1427 小鱼的数字游戏
- 编译alsa-lib, alsa-util以使用声卡
- 如何在ubuntu下查看隐藏的文件和文件夹