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 ;
}

Codeforces 758C-Unfair Poll的更多相关文章

  1. CodeFroces 758C - Unfair Poll

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

  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. 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 ...

  7. 【codeforces 758C】Unfair Poll

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

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

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

  9. Codeforces 392 C Unfair Poll(模拟)

    题意:老师点名顺序规则如下:第1排,第2排,……,第n-1排,第n排,第n-1排,……,第2排,第1排,第2排,……,第n-1排,第n排,……对于每排都是从左到右依次点名,问点名k个人后,所有人中最多 ...

  10. CF758C Unfair Poll

    题意: On the Literature lesson Sergei noticed an awful injustice, it seems that some students are aske ...

随机推荐

  1. MDX Step by Step 读书笔记(七) - Performing Aggregation 聚合函数之 Max, Min, Count , DistinctCount 以及其它 TopCount, Generate

    MDX 中最大值和最小值 MDX 中最大值和最小值函数的语法和之前看到的 Sum 以及 Aggregate 等聚合函数基本上是一样的: Max( {Set} [, Expression]) Min( ...

  2. 使用SpringBoot的推荐项目目录结构

    一.Spring Boot 推荐目录结构 (1)代码层的结构 根目录:com.springboot 1.工程启动类(ApplicationServer.java)置于com.springboot.bu ...

  3. 一个可以参考的JVM内存分配

    下面是java命令有关JVM内存分配的参数 JAVA_MEM_OPTS="" BITS=`java -version >& | -bit` if [ -n " ...

  4. eclipse default handler IHandler interface “the chosen operation is not enabled”

    NOTE: These two methods: Tip: Subclass AbstractHandler rather than implementing IHandler. but you ca ...

  5. swift常用第三方库

    网络 Alamofire:http网络请求事件处理的框架. Moya:这是一个基于Alamofire的更高层网络请求封装抽象层. Reachability.swift:用来检查应用当前的网络连接状况. ...

  6. Atitit 大json文件的结构化查看解决方案,高性能的jsonview  attilax总结.docx

    Atitit 大json文件的结构化查看解决方案,高性能的jsonview  attilax总结.docx 1.1. 实现目标:1 1.2. 实现key与value类型的..一直分析到非 jsonob ...

  7. 将自己写的HDL代码封装成带AXI总线的IP

    将自己写的HDL代码封装成带AXI总线的IP 1.Tools->create and package IP 2.create AXI4总线的IP 3.新建block design 4.点击右键, ...

  8. vue使用node的入门

    1.安装cnpm npm install -g cnpm --registry=https://registry.npm.taobao.org 验证是否安装 cnpm -v 2.安装vue cnpm ...

  9. SAP BW 数据库表命名规则

    SAP BW 数据库表命名规则 已有 315 次阅读2012/6/8 15:55 |系统分类:专业内容| SAP, 命名, 数据库表 Namings for Cube: /BI<C OR DIG ...

  10. 聊聊Python中的生成器和迭代器

    Python中有两个重要的概念,生成器和迭代器,这里详细记录一下. 1. 生成器 什么是生成器呢? 通过列表生成式,我们可以直接创建一个列表.但是,受到内存限制,列表容量肯定是有限的.而且,创建一个包 ...