CF758C 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.
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.
1 3 8 1 1
3 2 3
4 2 9 4 2
2 1 1
5 5 25 4 3
1 1 1
100 100 1000000000000000000 100 100
101010101010101 50505050505051 50505050505051
思路:
模拟。
实现:
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
ll n, m, k, x, y, maxn, minn, t;
int main()
{
cin >> n >> m >> k >> x >> y;
if (n == )
{
maxn = k / m + (k % m ? : );
minn = k / m;
t = y > k % m ? minn : maxn;
cout << maxn << " " << minn << " " << t << endl;
}
else
{
ll t = ( * n - ) * m;
ll tmp = k / t;
ll rem = k % t;
maxn = n > ? * tmp : tmp, minn = tmp;
t = (x == || x == n) ? minn : maxn;
if (rem)
{
if (rem > n * m)
{
maxn += ;
minn++;
ll p = (rem - n * m) / m;
ll q = (rem - n * m) % m;
ll nx = n - - p;
ll ny = q;
if (ny == )
{
nx++;
ny = m;
}
if (x < nx || x == nx && y > ny || x == n)
{
t++;
}
else
{
t += ;
}
}
else if (rem == n * m)
{
maxn++;
minn++;
t++;
}
else
{
if (rem > m)
maxn++;
else if (maxn == minn)
maxn++;
ll nx = rem / m;
ll ny = rem % m;
if (ny)
{
nx++;
}
else
{
ny = m;
}
if (!(x > nx || x == nx && y > ny))
{
t++;
}
}
}
cout << maxn << " " << minn << " " << t << endl;
}
return ;
}
CF758C Unfair Poll的更多相关文章
- 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 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 ...
- 【codeforces 758C】Unfair Poll
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- C. Unfair Poll 数学题,
http://codeforces.com/contest/758/problem/C 需要一个能够找到任意一个位置的步数的方法,就能解决三个问题. 预处理出one(row, col)表示第一次经过这 ...
- Codeforces 758C:Unfair Poll(思维+模拟)
http://codeforces.com/problemset/problem/758/C 题意:教室里有n列m排,老师上课点名从第一列第一排开始往后点,直到点到第一列第m排,就从第二列第一排开始点 ...
- CodeFroces 758C - Unfair Poll
题意: 老师点名,顺序是1 -- n -- 1 排为一个循环,每列为1 -- m的顺序, 问点到最多次数和最少次数的人的次数以及(x,y)被点的次数. 分析: 由于点名有循环,故可先判断出每一个循环每 ...
随机推荐
- JS中的存储机制
一.堆和栈的介绍 1.堆和队,是先进先出:栈,是先进后出,就跟水桶差不多: 2.存储速度:堆和队的存储速度较慢,栈的存储速度较快,会自动释放: 二.js中存储的类型 1.堆,一般用于复杂数据类型,存储 ...
- 跳转到AppStore 的不同位置办法
程序跳转到appstore中指定的应用 1.进入appstore中指定的应用NSString *str = [NSString stringWithFormat: ...
- 类的加载、时机、反射、模板设计、jdk7/jdk8新特性(二十六)
1.类的加载概述和加载时机 * A:类的加载概述 * 当程序要使用某个类时,如果该类还未被加载到内存中,则系统会通过加载,连接,初始化三步来实现对这个类进行初始化. * 加载 * 就是指将class文 ...
- iOS自定义提示弹出框(类似UIAlertView)
菜鸟一枚,大神勿喷.自己在牛刀小试的时候,发现系统的UIAlertView有点不喜欢,然后就自己自定义了一个UIAlertView,基本上实现了系统的UIAlertView,可以根据项目的需求修改UI ...
- SILVERLIGHT实现对HTML DOM的访问
实现对HTML DOM的访问.Silverlight 2在命名空间System.Windows.Browser下内置了很多对于HTML DOM访问和操作的支持,我们最常用的一个对象是HtmlEleme ...
- javascript之数组的6种去重方法
去重 var arr=[11,11,333,4,4,5,66,66,7]; // 方法一:在新数组内判断不存在时加入 var newarr1=[]; function quchong1(){ for( ...
- org.hibernate.hql.ast.QuerySyntaxException: Student is not mapped [from Student as stu where stu.sclass=?]
java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: t_aty_disease is not ...
- iOS 拼音 Swift K3Pinyin
iOS 系统方法支持直接获取拼音,避免了之前各种第三方引入各种MAP或者资源文件.下面是一个Swift版本的简单示例: // swift 4.0 func pinyin(_ string: Strin ...
- 机器学习--DIY笔记与感悟--①K-临近算法(2)
上一篇博客我手动写了KNN算法,并且之后用手写的算法预测了约会的成功率. 而今天,我在大神博客的指导下调用sklearn这个库来预测图片的内容. 一.前期准备 由于我这里使用的是mac版本,而skle ...
- hdoj3714【三分】
手动插姿势: 三分法可以应用于凸函数或者凹函数的求极值. 三分讲解:http://blog.csdn.net/pi9nc/article/details/9666627 三分模板:http://www ...