Codeforces 758C-Unfair Poll
1 second
256 megabytes
standard input
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:
- 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.
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).
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.
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;
题意: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的更多相关文章
- CodeFroces 758C - Unfair Poll
题意: 老师点名,顺序是1 -- n -- 1 排为一个循环,每列为1 -- m的顺序, 问点到最多次数和最少次数的人的次数以及(x,y)被点的次数. 分析: 由于点名有循环,故可先判断出每一个循环每 ...
- 【找规律】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 ...
- 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 ...
- CodeForces 758 C Unfair Poll
Unfair Poll 题意:一共有n排同学每排同学有m个人, 老师问问题有一个顺序, 先从第一排开始问,问完第一排的所有同学之后,再问第2排的,对于所有排的访问顺序为 1,2,3……n-1,n,n- ...
- C. Unfair Poll
http://codeforces.com/problemset/problem/758/C C. Unfair Poll time limit per test 1 second memory li ...
- 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 ...
- 【codeforces 758C】Unfair Poll
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces 758C:Unfair Poll(思维+模拟)
http://codeforces.com/problemset/problem/758/C 题意:教室里有n列m排,老师上课点名从第一列第一排开始往后点,直到点到第一列第m排,就从第二列第一排开始点 ...
- Codeforces 392 C Unfair Poll(模拟)
题意:老师点名顺序规则如下:第1排,第2排,……,第n-1排,第n排,第n-1排,……,第2排,第1排,第2排,……,第n-1排,第n排,……对于每排都是从左到右依次点名,问点名k个人后,所有人中最多 ...
- CF758C Unfair Poll
题意: On the Literature lesson Sergei noticed an awful injustice, it seems that some students are aske ...
随机推荐
- SQL2012 之 创建备份计划
打开数据库,选择 管理 → 右键维护计划→选择新建维护计划,填写计划名称,如下图: 修改维护计划参数,如下图: 工具箱->备份数据库任务,拖到计划里,如下图: 编辑“备份数据库”任务,如下图: ...
- 我是陌生人 Java中导入、导出Excel
我是陌生人 Java中导入.导出Excel 一.介绍 当前B/S模式已成为应用开发的主流,而在企业办公系统中,常常有客户这样子要求:你要把我们的报表直接用Excel打开(电信系统.银行系统).或者是: ...
- JAVA四则运算字符串解释器
最近学习到后缀表达式,于是基于后缀表达式的思想,写了一个四则运算解释器,输入字符串类型的四则运算表达式,可以直接得到结果,支持括号嵌套. 实现时主要考虑以下两点: 字符串中运算符和数字分离 运算符优先 ...
- MySQL -- Innodb的关闭
参数innodb_fast_shutdown控制着innodb的关闭模式,有三种取值: 0: innodb执行slow shutdown,在关闭之前要完成一次full purge和change ...
- arcgis server瓦片行列号计算
2013-08-01 arcgis server切图时会设置一个原点坐标,如果是经纬度坐标一般默认(x0,y0)=(-400,400)作为切图的起始点,即从这开始算行列号.假设切图的地图某点坐标为x, ...
- Android解决NDK not configured问题
问题描述: // Error:Execution failed for task ':SoftkeyApp:compileDebugNdk'. // > NDK not configured. ...
- 【Android】Eclipse性能优化,快捷方式,文档注释
快捷方式 方法注释的快捷键:ALT + SHIFT +J 格式化:Ctrl+Shift+F 把当前选中的文本全部变味大写:Ctrl+Shift+X 把当前选中的文本全部变为小写:Ctrl+Shift+ ...
- 实现div里的img图片水平垂直居中
body结构 <body> <div> <img src="1.jpg" alt="haha"> </div> ...
- [firefox] Scrapbook Plus的改进版Scrapbook X
我在两年前的博文<Firefox上一些我用于知识管理的扩展> 里面提到过我在用Scrapbook Plus这个Firefox扩展, 用它来撷取网页构建自己的知识库(可以加标注.可以搜索.可 ...
- [转]Object.keys()和for in的排序问题
原文地址:https://www.jianshu.com/p/a086ff48be6e Object.keys()和for in 具有相同的排列顺序 如果属性名的类型是Number,那么Object. ...