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: ...
随机推荐
- 详解Centos7 修改mysql指定用户的密码
本文介绍了Centos7 修改mysql指定用户的密码,具体如下: 1.登陆mysql或者mariadb(两种任选其一) [root@localhost ~]# mysql -u root [root ...
- Python yield详解***
yield的英文单词意思是生产,有时候感到非常困惑,一直没弄明白yield的用法. 只是粗略的知道yield可以用来为一个函数返回值塞数据,比如下面的例子: def addlist(alist): f ...
- WebFrom基础
ASP.NET WebForm C/S B/S客人 - 用户 要土豆丝 - 给IIS发送请求 ,IIS就相当于是服务员 通知厨房 - IIS把用户要想看到的ASPX告知.NET框架 厨房炒菜 - .n ...
- [转]oracle 12c 中的分页子句
转自:http://blog.itpub.net/271063/viewspace-1061279/ -- 连接数据库 创建测试用户-- Connected to Oracle Database 12 ...
- mysql-5.6.20主从同步错误之Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND
mysql-5.6.20主从同步错误之Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND 方法一: 1.Error_code: 1032; ha ...
- Python开发一个简单的BBS论坛
项目:开发一个简单的BBS论坛 需求: 整体参考“抽屉新热榜” + “虎嗅网” 实现不同论坛版块 帖子列表展示 帖子评论数.点赞数展示 在线用户展示 允许登录用户发贴.评论.点赞 允许上传文件 帖子可 ...
- Python web框架——Tornado
Tornado是一个Python Web框架和异步网络库,最初由FriendFeed开发.通过使用非阻塞网络I / O,Tornado可以扩展到数万个开放连接,使其成为需要长时间连接每个用户的长轮询, ...
- Java——复制txt文件
将源文件复制到目标文件,同时输出源文件内容,需要提供一个源文件和目标文件路径参数(如果不存在则自动创建) public static void copyTxt(String sourceFile, S ...
- centos7上mysql无法启动也没有日志
报错的原因就是 [root@localhost duanxinli]# journalctl -xe-- Subject: Unit mysqld.service has begun start-up ...
- spring mvc 映射器和适配器
映射器和适配器 1.非注解的映射器和适配器 a. 入门程序中的单个映射 BeanNameUrlHandlerMapping SimpleControllerHandlerAdapter b.另一种ma ...