Codeforces758C
C. Unfair Poll
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
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
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;
数学题, 做法很丑。
//2017.01.20
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int main()
{
int n, m, x, y;
long long k;
long long maximum, minimum, cnt;
while(cin>>n>>m>>k>>x>>y)
{
if(n==){
if(k%m==)maximum = minimum = k/m;
else{
maximum = k/m+;
minimum = maximum-;
}
}else{
long long row = k/m;
if(row*m != k)row++;
if(n==)maximum = (row+)/n;
else maximum = (row-)/(n-)+;
minimum = (row+n-)/(*n-);
if(minimum*(*n-) == (row+n-) && row*m != k)
minimum--;
}
int pos = (x-)*m+y;
if(n==)
{
if(pos <= k%m)cnt = maximum;
else cnt = minimum;
}else
{
long long cyc = k/(m*(*n-));
cnt = (x==||x==n) ? cyc : *cyc;
long long other = k-cyc*(m*(*n-));
if(other < pos)cnt+=;
else if(((n--x)*m+y)>(other-m*n)||(x==||x==n))cnt+=;
else cnt+=;
} cout<<maximum<<" "<<minimum<<" "<<cnt<<endl; } return ;
}
Codeforces758C的更多相关文章
- 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 ...
随机推荐
- Git上传文件
最近开始折腾node.js,顺便学习了Git上传的相关知识,找了许多关于Git如何上传项目的相关资料,最终发现一篇比较简易完整的文章, 在此分享一下喜悦的心情!下文是使用Git上传的完整教程: 将文件 ...
- BNU OJ 51005 BQG's Quadrilateral Bricks
#include<cstdio> #include<cstring> #include<cmath> #include<vector> #include ...
- appium通过WiFi连接真机进行测试
http://www.th7.cn/Program/Android/201507/514602.shtml appium通过WiFi连接真机进行测试 2015-07-24 19:43:07CSDN ...
- HDU 4408 Minimum Spanning Tree 最小生成树计数
Minimum Spanning Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- c#之向ftp服务器传文件
.Net提供了FtpWebRequest类,代码如下: using System; using System.Collections.Generic; using System.IO; using S ...
- iOS js oc相互调用(JavaScriptCore)
http://blog.csdn.net/lwjok2007/article/details/47058795
- 必须熟悉的vim快捷键操作
转载请表明出处http://www.dabu.info/?p=801 Vim/Vi 没有菜单,只有命令 Vim/Vi 工作模式介绍:插入模式 和 命令模式 是vi的两个基本模式.——插入模式 ,是用 ...
- Java中的 List Set Map
类层次关系如下: Collection ├List │├LinkedList │├ArrayList │└Vector │ └Stack └Set Map ├Hashtable ├HashMap └W ...
- HDU1429 bfs
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- Struts加入拦截器后取不到页面参数
在Struts2的demo项目中添加了一个简单的拦截器,突然发现,Action中取不到页面的参数了 这也是很蛋疼的事情,还好这个比较简单,稍微一查就发现问题: Struts2中很多的功能是用拦截器实现 ...