题意:

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:

  1. the maximum number of questions a particular pupil is asked,
  2. the minimum number of questions a particular pupil is asked,
  3. 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 nmkx and y (1 ≤ n, m ≤ 100, 1 ≤ k ≤ 1018, 1 ≤ x ≤ n, 1 ≤ y ≤ m).

Output

Print three integers:

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

思路:

模拟。

实现:

 #include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
ll n, m, k, x, y, maxn, minn, t;
int main()
{
cin >> n >> m >> k >> x >> y;
if (n == )
{
maxn = k / m + (k % m ? : );
minn = k / m;
t = y > k % m ? minn : maxn;
cout << maxn << " " << minn << " " << t << endl;
}
else
{
ll t = ( * n - ) * m;
ll tmp = k / t;
ll rem = k % t;
maxn = n > ? * tmp : tmp, minn = tmp;
t = (x == || x == n) ? minn : maxn;
if (rem)
{
if (rem > n * m)
{
maxn += ;
minn++;
ll p = (rem - n * m) / m;
ll q = (rem - n * m) % m;
ll nx = n - - p;
ll ny = q;
if (ny == )
{
nx++;
ny = m;
}
if (x < nx || x == nx && y > ny || x == n)
{
t++;
}
else
{
t += ;
}
}
else if (rem == n * m)
{
maxn++;
minn++;
t++;
}
else
{
if (rem > m)
maxn++;
else if (maxn == minn)
maxn++;
ll nx = rem / m;
ll ny = rem % m;
if (ny)
{
nx++;
}
else
{
ny = m;
}
if (!(x > nx || x == nx && y > ny))
{
t++;
}
}
}
cout << maxn << " " << minn << " " << t << endl;
}
return ;
}

CF758C Unfair Poll的更多相关文章

  1. Codeforces758C Unfair Poll 2017-01-20 10:24 95人阅读 评论(0) 收藏

    C. Unfair Poll time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. 【找规律】Codeforces Round #392 (Div. 2) C. Unfair Poll

    C. Unfair Poll time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  3. Codeforces Round #392 (Div. 2) Unfair Poll

    C. Unfair Poll time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. CodeForces 758 C Unfair Poll

    Unfair Poll 题意:一共有n排同学每排同学有m个人, 老师问问题有一个顺序, 先从第一排开始问,问完第一排的所有同学之后,再问第2排的,对于所有排的访问顺序为 1,2,3……n-1,n,n- ...

  5. C. Unfair Poll

    http://codeforces.com/problemset/problem/758/C C. Unfair Poll time limit per test 1 second memory li ...

  6. 【codeforces 758C】Unfair Poll

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. C. Unfair Poll 数学题,

    http://codeforces.com/contest/758/problem/C 需要一个能够找到任意一个位置的步数的方法,就能解决三个问题. 预处理出one(row, col)表示第一次经过这 ...

  8. Codeforces 758C:Unfair Poll(思维+模拟)

    http://codeforces.com/problemset/problem/758/C 题意:教室里有n列m排,老师上课点名从第一列第一排开始往后点,直到点到第一列第m排,就从第二列第一排开始点 ...

  9. CodeFroces 758C - Unfair Poll

    题意: 老师点名,顺序是1 -- n -- 1 排为一个循环,每列为1 -- m的顺序, 问点到最多次数和最少次数的人的次数以及(x,y)被点的次数. 分析: 由于点名有循环,故可先判断出每一个循环每 ...

随机推荐

  1. springboot如何使用外部tomcat容器

    一般情况spring-boot-starter-web是自带tomcat(即springboot内嵌tomcat),所以打包直接生成jar包,用java -jar命令就可以启动. 但,有时我们希望用w ...

  2. 一个基本的spring+mybatis所需要的包

    spring+mybatis需要的包:org.springframework.spring-webmvc(spring框架DispatcherServlet需要,spring-webmvc会依赖spr ...

  3. LIS n^2&nlogn模板

    LIS nlogn模板 http://acm.hdu.edu.cn/showproblem.php?pid=1950 #include <iostream> #include <st ...

  4. HDU2594 Simpsons’ Hidden Talents —— KMP next数组

    题目链接:https://vjudge.net/problem/HDU-2594 Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Oth ...

  5. 计算机学院大学生程序设计竞赛(2015’12)Happy Value

    Happy Value Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  6. expect的安装与使用

    expect的安装与使用 是什么 expect 是用来进行自动化控制和测试的工具.主要是和交互式软件telnet ftp ssh 等进行自动化的交互. 如何安装 1.检测是否安装 ls /usr/bi ...

  7. vue之安装配置

    直接上图

  8. 【转】构建Maven项目自动下载jar包

    原文地址:https://blog.csdn.net/gfd54gd5f46/article/details/54973954 使用Maven 自动下载jar包 右键单击项目,将项目 转换成Maven ...

  9. 禁用选择文本功能user-select

    有时候,我们为了用户体验,需要禁用选择文本功能. 这需要用到一个CSS属性:user-select,user-select的文档点这里 user-select有两个值:none:用户不能选择文本tex ...

  10. Mac下Apache服务器和webDav服务器快速配置

    当自己在家敲代码需要发请求时,就可以配置本地Apache,Mac电脑自带的服务器.这个比windows上的本地服务器还要好用,下面写下最快速配置方案. 0.在开始之前需要给自己的电脑设置下开机密码,想 ...