Codeforces758C Unfair Poll 2017-01-20 10:24 95人阅读 评论(0) 收藏
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.
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
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;
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string> using namespace std; int main()
{
long long m,n,k,x,y;
while(~scanf("%I64d %I64d %I64d %I64d %I64d",&n,&m,&k,&x,&y))
{
if(k==m&&n==1)
{
printf("1 1 1\n");
continue;
}
if(k<=m)
{
if(x==1&&y<=k)
printf("1 0 1\n");
else
printf("1 0 0\n");
continue;
} if(n==1)
{
long long ttt=k/m;
long long tt=k%m;
if(y<=tt)
{
if(tt==0)
printf("%I64d %I64d %I64d\n",ttt,ttt,ttt);
else
printf("%I64d %I64d %I64d\n",ttt+1,ttt,ttt+1);
}
else
{
if(tt==0)
printf("%I64d %I64d %I64d\n",ttt,ttt,ttt);
else
printf("%I64d %I64d %I64d\n",ttt+1,ttt,ttt);
}
continue;
}
if(n==2)
{
long long ttt=k/(m*2);
long long tt=k%(m*2);
long long ttc=(x-1)*m+y;
if(tt==0)
printf("%I64d %I64d %I64d\n",ttt,ttt,ttt);
else
{
if(tt<ttc)
printf("%I64d %I64d %I64d\n",ttt+1,ttt,ttt);
else
printf("%I64d %I64d %I64d\n",ttt+1,ttt,ttt+1);
}
continue;
}
k-=m;
long long int cnt=k/(m*(n-1));
long long int md=k%(m*(n-1));
long long int zheng=(x-1)*m+y-m;
long long int fan=(n-x)*m+y-m;
if(cnt%2==1)
{
if(x==1)
{
if(md==0)
printf("%I64d %I64d %I64d\n",cnt,cnt/2+1,cnt/2+1);
else
{
if(fan>md)
printf("%I64d %I64d %I64d\n",cnt+1,cnt/2+1,cnt/2+1);
else
printf("%I64d %I64d %I64d\n",cnt+1,cnt/2+1,cnt/2+2); } }
else if(x==n)
{
if(md==0)
printf("%I64d %I64d %I64d\n",cnt,cnt/2+1,cnt/2+1);
else
{
printf("%I64d %I64d %I64d\n",cnt+1,cnt/2+1,cnt/2+1);
}
}
else if(fan>md)
{
if(md==0)
printf("%I64d %I64d %I64d\n",cnt,cnt/2+1,cnt);
else
printf("%I64d %I64d %I64d\n",cnt+1,cnt/2+1,cnt);
}
else
{
printf("%I64d %I64d %I64d\n",cnt+1,cnt/2+1,cnt+1);
}
}
else
{
if(x==1)
{
if(md==0)
printf("%I64d %I64d %I64d\n",cnt,cnt/2,cnt/2+1);
else
{
printf("%I64d %I64d %I64d\n",cnt+1,cnt/2,cnt/2+1);
} }
else if(x==n)
{
if(md==0)
printf("%I64d %I64d %I64d\n",cnt,cnt/2,cnt/2);
else
{
if(zheng>md)
printf("%I64d %I64d %I64d\n",cnt+1,cnt/2,cnt/2);
else
printf("%I64d %I64d %I64d\n",cnt+1,cnt/2,cnt/2+1);
}
}
else if(zheng>md)
{
if(md==0)
printf("%I64d %I64d %I64d\n",cnt,cnt/2,cnt);
else
printf("%I64d %I64d %I64d\n",cnt+1,cnt/2,cnt);
}
else
{
printf("%I64d %I64d %I64d\n",cnt+1,cnt/2,cnt+1);
}
} } return 0;
}
Codeforces758C Unfair Poll 2017-01-20 10:24 95人阅读 评论(0) 收藏的更多相关文章
- 菜鸟学习-C语言函数参数传递详解-结构体与数组 分类: C/C++ Nginx 2015-07-14 10:24 89人阅读 评论(0) 收藏
C语言中结构体作为函数参数,有两种方式:传值和传址. 1.传值时结构体参数会被拷贝一份,在函数体内修改结构体参数成员的值实际上是修改调用参数的一个临时拷贝的成员的值,这不会影响到调用参数.在这种情况下 ...
- config 数据库字符串的读取、修改 分类: WebForm 2014-12-16 10:24 203人阅读 评论(0) 收藏
config数据库字符串: <connectionStrings> <add name="MyWebDataString" connectionString= ...
- 博弈论入门小结 分类: ACM TYPE 2014-08-31 10:15 73人阅读 评论(0) 收藏
文章原地址:http://blog.csdn.net/zhangxiang0125/article/details/6174639 博弈论:是二人或多人在平等的对局中各自利用对方的策略变换自己的对抗策 ...
- C语言基础总结 分类: iOS学习 c语言基础 2015-06-11 10:08 23人阅读 评论(0) 收藏
//欲练此功必先自宫!!! //第一天:C语言的基础 //进制 //2进制, 10进制, 8进制, 16进制 //注:8进制数前加0, 16进制数前加0x ...
- DNA Sorting 分类: POJ 2015-06-23 20:24 9人阅读 评论(0) 收藏
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 88690 Accepted: 35644 Descrip ...
- 【C#小知识】C#中一些易混淆概念总结(二)--------构造函数,this关键字,部分类,枚举 分类: C# 2014-02-03 01:24 1576人阅读 评论(0) 收藏
目录: [C#小知识]C#中一些易混淆概念总结--------数据类型存储位置,方法调用,out和ref参数的使用 继上篇对一些C#概念问题进行细节的剖析以后,收获颇多.以前,读书的时候,一句话一掠而 ...
- winform timespan 两个时间的间隔(差) 分类: WinForm 2014-04-15 10:14 419人阅读 评论(0) 收藏
TimeSpan 结构 表示一个时间间隔. 先举一个小例子:(计算两个日期相差的天数) 代码如下: DateTime dt = DateTime.Now.ToShortDateString(yyyy ...
- 全面解析sizeof(上) 分类: C/C++ StudyNotes 2015-06-15 10:18 188人阅读 评论(0) 收藏
以下代码使用平台是Windows7 64bits+VS2012. sizeof是C/C++中的一个操作符(operator),其作用就是返回一个对象或者类型所占的内存字节数,使用频繁,有必须对齐有个全 ...
- Financial Management 分类: POJ 2015-06-11 10:51 12人阅读 评论(0) 收藏
Financial Management Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 164431 Accepted: ...
随机推荐
- JSTL-c:forEach标签详解
c:forEach基本格式: <c:forEach var="每个变量名字" items="要迭代的list" varStatus="每个对象的 ...
- 关于HDU 5952的那些事
内容过后再贴,先发表一下心情和感悟. 这个题,我TLE了十多发,后来看了别人的题解,思路是一样的,他做了剪枝的我也做了,为何他的能过的我的超时?后来发现一个不是主要问题的问题:大家的图存储用的都是前向 ...
- 十二.jQuery源码解析之.eq().first().last().slice()
eq(index):将集合中的索引为index的元素提取出来. first():返回集合中的第一个元素. .last():防护集合中的最后一个元素. .slice(start[,end]):返回集合中 ...
- 原生态Vim使用快捷键
我的第一篇博客,凌晨2点加班不想睡,随便写点.本人菜鸟一个,努力学习,争取成为大神.. 第一篇写点什么东西呢,我目前是搞运维的,俗话说"工欲善其事必先利其器",Vim作为最基本的工 ...
- 461. Hamming Distance + 477. Total Hamming Distance
▶ 与 Hamming 距离相关的两道题. ▶ 461. 求两个数 x 与 y 的哈夫曼距离. ● 代码,4 ms,对 x 和 y 使用异或,然后求值为 1 的位的个数. class Solutio ...
- servlet笔记1
Myeclipse关于Servlet项目文件的组织方面,如下: WEB-INF:这个目录名称和位置是固定的,放置在该目录下的文件或目录,对外界来说的封闭的,也就是客户端无法用http的任何方式访问到其 ...
- 解决Notepad++ Plugin Manager无法加载插件的方法
今天正好安装了Notepad++,结果发现Plugin Manager里插件一个也没有,网上对应的方法都没有,最后无意间看到Plugin Manager Settings 里的提示,试了一下居然成功了 ...
- VS2008项目移植到Linux
不少人都遇到过这种情况:在Windows下用Visual Studio工具开发的程序需要移植到Linux系统中,做成Linux版本的,但程序比较大,在Linux上又离不开Make,手动编写Makefi ...
- Python pip配置国内源
众所周知,Python使用pip方法安装第三方包时,需要从 https://pypi.org/ 资源库中下载,但是会面临下载速度慢,甚至无法下载的尴尬,这时,你就需要知道配置一个国内源有多么重要了,通 ...
- qemu模拟器下编译运行基于riscv指令集的Linux操作系统
基本原理: 在物理服务器Ubuntu14.04上安装qemu模拟器,模拟器中运行基于riscv指令集编译的linux镜像文件. 用到的工具包括: riscv-qemu(模拟器,可以模拟运行risc ...