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 ...
随机推荐
- 微软BI 之SSIS 系列 - 对于平面文件中 NULL 值处理过程中容易极易混淆的几个细节
开篇介绍 最近有人问我有关文件处理中空值处理的相关问题: OLE DB Destination 中的 Keep Nulls 如何控制 NULL 值的显示? 为什么选中了 Keep Nulls 但是数据 ...
- awesomes前端资源库网站
https://www.awesomes.cn http://www.cnblogs.com/jiujiaoyangkang/p/4998518.html (web app自适应框架flexible) ...
- Spark机器学习(10):ALS交替最小二乘算法
1. Alternating Least Square ALS(Alternating Least Square),交替最小二乘法.在机器学习中,特指使用最小二乘法的一种协同推荐算法.如下图所示,u表 ...
- CentOS 7源码安装zabbix
一.Zabbix简介 zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案.zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供灵活的通知机制以让系统 ...
- 【PMP】项目的定义和特点
1.定义 项目是为创建独特的产品.服务和成果而进行的的临时性工作. 2.特点 2.1 独特的产品.服务或成果 实现项目目标可能产生一个或多个可交付成果.例如:即便采用相同的材料或者相同的施工单位来建设 ...
- phpBB3.2开发环境配置
从Github导出项目 如果只是查看代码, 可以直接clone官方的git https://github.com/phpbb/phpbb.git . 如果需要开发, 就fork一下再从自己的Git里c ...
- 研究傅里叶变换的一本好书<<快速傅里叶变换及其C程序>>
快速傅里叶变换及其C程序 <快速傅里叶变换及其C程序>是中国科学技术大学出版社出版的.本书系统地介绍了傅里叶变换的理论和技术,内容包括傅里叶变换(FT)的定义.存在条件及其性质,离散傅里叶 ...
- jquery ajax IE
在ie上会出现,get/post 只调用一次的现象 解决方法: cache:false http://stackoverflow.com/questions/8841425/how-to-set-ca ...
- 【ML】Predict and Constrain: Modeling Cardinality in Deep Structured Prediction -预测和约束:在深度结构化预测中建模基数
[论文标题]Predict and Constrain: Modeling Cardinality in Deep Structured Prediction (35th-ICML,PMLR) [ ...
- [ci]jenkins-slave的添加(vm模式,通过ssh和jnlp)
jenkins-slave的添加-在vm上通过jnlp方式 参考:http://www.cnblogs.com/sparkdev/p/7102622.html 下载 slave.jar和slave-a ...