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: ...
随机推荐
- 桶排序与快速排序算法结合-python实现
#-*- coding: UTF-8 -*- import numpy as np from QuickSort import QuickSort def BucketSort(a, n): barr ...
- jsp获取请求头信息
<%@ page language="java" import="java.util.*" contentType="text/html; ch ...
- 《Linux内核精髓:精通Linux内核必会的75个绝技》一HACK #10 Fair Group Scheduling
HACK #10 Fair Group Scheduling 本节介绍Cgroup之一.管理CPU资源的Fair Group Scheduling.Fair Group SchedulingFair ...
- 线程的等待方法:join
其实多线程最复杂的地方在于不同线程间的同步问题,这其中会涉及到先后执行问题.共享变量问题等.这篇文章我们主要来开个头,看一下join方法. using System; using System.Thr ...
- django rest_framework 框架的使用
django 的中间件 csrf Require a present and correct csrfmiddlewaretoken for POST requests that have a CSR ...
- python的with用法(参考)
一.With语句是什么? 有一些任务,可能事先需要设置,事后做清理工作.对于这种场景,Python的with语句提供了一种非常方便的处理方式.一个很好的例子是文件处理,你需要获取一个文件句柄,从文件中 ...
- python一些不错的东西
1 cmd命令行写代码的加强版 ipython 直接用pip安装就可以 php install Ipython 2 不错的数据分析 机器语言的 Python(x,y)是一个基于python的科 ...
- 「小程序JAVA实战」小程序视频播放的时候生命周期的控制(56)
转自:https://idig8.com/2018/09/23/xiaochengxujavashizhanxiaochengxushipinbofangdeshihoushengmingzhouqi ...
- sql中纵表变横表
纵表格式如图所示: 查询sql语句如下: ),content)content,Date from SummerChina ' 变成横表如图所示: 纵表变横表sql语句如下: select Time, ...
- 【转】关于BeanUtils.copyProperties的用法和优缺点
一.简介: BeanUtils提供对Java反射和自省API的包装.其主要目的是利用反射机制对JavaBean的属性进行处理.我们知道,一个JavaBean通常包含了大量的属性,很多情况下,对Jav ...