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: ...
随机推荐
- VMware vSphere Client下增加虚拟机磁盘空间的方法
随着系统运维时间的增长,磁盘就日益的损耗,如果遇到虚拟机报磁盘空间不足怎么办?还好,我们可以通过磁盘阵列增加磁盘空间,然后扩容到虚拟机中去. 对于linux虚拟机磁盘扩容的方案有两种,一种就是原有的实 ...
- RTNETLINK answers: File exists
问题: 重启网络时报错如下 >>/etc/init.d/network start RTNETLINK answers: File exists 分析: /etc/init.d/netwo ...
- DP系列——树形DP(Codeforces543D-Road Improvement)
一.题目链接 http://codeforces.com/problemset/problem/543/D 二.题意 给一棵树,一开始所有路都是坏的.询问,以每个节点$i$为树根,要求从树根节点到其他 ...
- ubuntu,debian root密码忘记破解
开机启动的时候在grub引导时,按住e进行启动项编辑,修改开头有linux字符及最后又ro字符的行,将ro字符改为rw single init=/bin/bash按F10键进行启动即可进入单用户模式, ...
- Wasserstein距离 和 Lipschitz连续
EMD(earth mover distance)距离: 在计算机科学与技术中,地球移动距离(EMD)是一种在D区域两个概率分布距离的度量,就是被熟知的Wasserstein度量标准.不正式的说,如果 ...
- IOS调试技巧:当程序崩溃的时候怎么办 xcode调试
转自:http://www.ityran.com/archives/1143 ------------------------------------------------ 欢迎回到当程序崩溃的时候 ...
- Memcpy, blockcopy的进一步理解
using System; using System.Runtime.InteropServices; using System.IO; namespace tx { struct ST { publ ...
- AOP术语
1.连接点(Joinpoint) 程序执行的某个特定位置:如类开始初始化前,类初始化后,类某个方法调用前,调用后,方法跑出异常后.一个类或一段程序代码拥有一些具有边界性质的特定点.这些代码中的特定点就 ...
- 小菜鸟入门nginx
实现功能:端口进行转发 比如我实际运行的是·http:localhost:5000 但是我想通过localhost:80 进行访问. 过程 1 下载nginx 2 解压到某个目录(比如我放在C盘根目录 ...
- 什么是Emit,什么是反射,二者区别到底是什么?(转)
Emit的准确定义,我们看看微软给出的答案 System.Reflection.Emit 命名空间包含{ 允许编译器或工具发出元数据和发出 Microsoft 中间语言 (MSIL) ,并可选择在磁盘 ...