题意:

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. usaco2008 nov 区间异或求和

    Problem 11: Switching Lights [LongFan, 2008] Farmer John tries to keep the cows sharp by letting the ...

  2. 阿里云短信服务发送短信验证码(JAVA开发此功能)

    开发此功能需注册阿里云账号,并开通短信服务(免费开通) 充值后,不会影响业务的正常使用!(因为发送验证类短信:1-10万范围的短信是0.045元/条).开发测试使用,充2块钱测试足够了 可参考阿里云官 ...

  3. Python(1)(安装与基本使用)

    1.Python的下载和安装我就不废话了,百度上都有. 我安装的是Python 3.4.3 64bit 安装完之后,打开Cmd,输入Python 显示以上相同,按照百度的意思就是安装成功. 2.配置环 ...

  4. RecyclerView 局部刷新(获取viewHolder 去刷新)

    RecyclerView.ViewHolder viewHolder = mRecyclerView.findViewHolderForAdapterPosition(i); if (viewHold ...

  5. ${varname:-defaultvalue}

    ${varname:-defaultvalue}的意思是:如果varname存在且非null,则返回其值:否则,返回defaultvalue. 用途:如果变量未定义,则返回默认值.

  6. Python的多进程锁的使用

    很多时候,我们需要在多个进程中同时写一个文件,如果不加锁机制,就会导致写文件错乱 这个时候,我们可以使用multiprocessing.Lock() 我一开始是这样使用的: import multip ...

  7. 使用strtok_s函数从一个字符串中分离出单词

    下面的代码从含有多个结束符的字符串中分离出单词来,需要对strtok_s有清楚的认识.这段代码是我在写一个处理文件中单词个数时用来分离读取到的字符串中的单词时写的,亲测可用~ 1 2 3 4 5 6 ...

  8. 002--linux基础命令

    退出终端命令:exit 关闭Linux系统的命令:init 0 切换虚拟终端的方法:Ctrl+Alt+F[1-6] who命令 :查看有多少个终端打开着 whoami命令:获取当前用户名 date命令 ...

  9. 在Emacs下用C/C++编程(转载)

    转自:http://www.caole.net/diary/emacs_write_cpp.html Table of Contents 版权说明和参考文献 参考文献: 版权说明: 序 基本流程 基本 ...

  10. hdoj1028;他们说这题叫dp...

    #include<cstdio> #include<string> #include<iostream> #include<vector> #inclu ...