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 ...
随机推荐
- 把中文版NetBeans改成英文版
不管你从官网下的是英文版还是中文版,安装之后操作界面都是中文的.这是因为NetBeans会根据你的操作系统自动设置界面语言,并且没有提供更改的功能.解决的方法也很简单,下面介绍我用过的两种方法: 方法 ...
- PAT (Advanced Level) 1030. Travel Plan (30)
先处理出最短路上的边.变成一个DAG,然后在DAG上进行DFS. #include<iostream> #include<cstring> #include<cmath& ...
- 计算机学院大学生程序设计竞赛(2015’12) 1009 The Magic Tower
#include<cmath> #include<cstdio> #include<cstring> #include<algorithm> using ...
- 哈夫曼树压缩C#算法(huffman)
算法原理:http://www.cnblogs.com/skywang12345/p/3706833.html. 上代码: using System; using System.Collections ...
- 数据降维技术(2)—奇异值分解(SVD)
上一篇文章讲了PCA的数据原理,明白了PCA主要的思想及使用PCA做数据降维的步骤,本文我们详细探讨下另一种数据降维技术—奇异值分解(SVD). 在介绍奇异值分解前,先谈谈这个比较奇怪的名字:奇异值分 ...
- CentOS 6.4 x64 postfix + dovecot + 虚拟用户认证
第一, 首先必须安装 apacache mysql php CentOS 直接使用 yum 安装 yum -y install httpd httpd-devel mysql php-mysql ...
- jsoup -- xml文档解析
jsoup -- xml文档解析 修改 https://jsoup.org/cookbook/modifying-data/set-attributes https://jsoup.org/cookb ...
- shell字符串操作之cut---实现字符串截取
shell中(字符串截取) cut是以每一行为一个处理对象的,这种机制和sed是一样的.(关于sed的入门文章将在近期发布) 2 cut一般以什么为依据呢? 也就是说,我怎么告诉cut我想定位到的剪切 ...
- 【POJ2104】【HDU2665】K-th Number 主席树
[POJ2104][HDU2665]K-th Number Description You are working for Macrohard company in data structures d ...
- Eclipse perl的IDE环境插件-EPIC
前提:1.安装好perl环境:ActivePerl(验证方法:cmd中输入 perl -v 看是否有反应~) 2.安装Eclipse 3.0以上版本 可选:安装PadWalker包,主要是全局变量跟踪 ...