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:

  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
output
input
output
input
output
input
output
Note

The order of asking pupils in the first test:

  1. the pupil from the first row who seats at the first table, it means it is Sergei;
  2. the pupil from the first row who seats at the second table;
  3. the pupil from the first row who seats at the third table;
  4. the pupil from the first row who seats at the first table, it means it is Sergei;
  5. the pupil from the first row who seats at the second table;
  6. the pupil from the first row who seats at the third table;
  7. the pupil from the first row who seats at the first table, it means it is Sergei;
  8. the pupil from the first row who seats at the second table;

The order of asking pupils in the second test:

  1. the pupil from the first row who seats at the first table;
  2. the pupil from the first row who seats at the second table;
  3. the pupil from the second row who seats at the first table;
  4. the pupil from the second row who seats at the second table;
  5. the pupil from the third row who seats at the first table;
  6. the pupil from the third row who seats at the second table;
  7. the pupil from the fourth row who seats at the first table;
  8. the pupil from the fourth row who seats at the second table, it means it is Sergei;
  9. the pupil from the third row who seats at the first table;

题意:n行m列的学生,老师从头开始点名第一排和最后一排每个周期只点一次。周期如图

题解:n==1 和 n==2单独处理,其他情况先算出有多少个周期,再讨论剩下部分能给三个答案加多少,特别注意一个周期都没有的情况。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
long long n,m;
long long k;
long long x,y;
long long maxx,minn,ans;
long long T,t;
long long res = ;
long long time = ; void solve()
{
T=*m*n - *m;
t=n*m;
time = k/T;
res = k%T;
if(res == )
maxx = time*;
if(res <= m)
maxx = max(time*,time+);
else if(res <= t)
maxx = time*+;
else if(res < T)
maxx = time*+; if(res < t )
minn = time;
else
minn = time+; if(x == || x == n)
ans+=time;
else
ans+=time*; long long cnt = ;
for(long long i=;i<=n;i++){
for(long long j=;j<=m;j++){
cnt++;
if(cnt > res)
break;
if(x == i && y == j)
ans++;
}
}
for(long long i=n-;i>=;i--){
for(long long j=;j<=m;j++){
cnt++;
if(cnt > res)
break;
if(x == i && y == j)
ans++;
}
}
} int main()
{
cin>>n>>m>>k>>x>>y; if( n== ){
T=m;
res = k%T;
time = k/T;
maxx = ((res==)?(time):(time+));
minn = time;
ans = ((res>=y)?(time+):time);
}
else if(n == ){
T=n*m;
res = k%T;
time = k/T;
maxx = ((res==)?(time):(time+));
minn = time;
ans = ((res>=(x-)*y+y)?(time+):time);
}
else{
solve();
} cout<<maxx<<" "<<minn<<" "<<ans<<endl; return ;
}

最新文章

  1. php函数获取真实客户端IP地址
  2. 怎么计算Oracle的表一条记录占用空间的大小
  3. C#学习笔记 -- Attribute
  4. ACM/ICPC 之 模拟 (HNUOJ 13391-换瓶模拟)
  5. Node.js 字体格式转换 ttf2eot ttf2woff ttf2svg
  6. php计算中英文混搭字符串长度
  7. ubuntu搭建svn服务器(转)
  8. 所有文章都迁移到我自己的博客了:http://blog.neazor.com
  9. 【Python】Django Model 怎么使用 UUID 作为主键?
  10. RepositoryItemComboBox 用法1
  11. REDHAT YUM使用网易源
  12. 2014年度辛星css教程夏季版第五节
  13. 【行为型】Command模式
  14. ADO.Net总结
  15. 水池(DFS)
  16. polling轮询和comet
  17. 改进的Bresenham算法
  18. Lambda表达式基础
  19. api接口token验证
  20. Node笔记四

热门文章

  1. JAVA分库分表的实现方案
  2. [剑指Offer]5.二维数组中的查找
  3. 反射简化switch语句
  4. R8500 MPv2 版本 刷 Kong编译的 ddwrt 后,使用Entware-ng 安装opkg安装第三方软件
  5. [svc]证书各个字段的含义
  6. FROM USE CASES TO TEST CASES
  7. 【emWin】例程二十:窗口对象——Dropdown
  8. 【网络编程】——ne-snmp开发实例1
  9. Java知多少(35)Object类
  10. MYSQL + MHA +keepalive + VIP安装配置(一)--MYSQL安装配置