http://codeforces.com/problemset/problem/758/C

C. Unfair Poll
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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:

  1. the maximum number of questions a particular pupil is asked,
  2. the minimum number of questions a particular pupil is asked,
  3. 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.

Input

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).

Output

Print three integers:

  1. the maximum number of questions a particular pupil is asked,
  2. the minimum number of questions a particular pupil is asked,
  3. how many times the teacher asked Sergei.
Examples
Input
1 3 8 1 1
Output
3 2 3
Input
4 2 9 4 2
Output
2 1 1
Input
5 5 25 4 3
Output
1 1 1
Input
100 100 1000000000000000000 100 100
Output
101010101010101 50505050505051 50505050505051
Note

The order of asking pupils in the first test:

  1. the pupil from the first row who seats at the first table, it means it is Sergei;
  2. the pupil from the first row who seats at the second table;
  3. the pupil from the first row who seats at the third table;
  4. the pupil from the first row who seats at the first table, it means it is Sergei;
  5. the pupil from the first row who seats at the second table;
  6. the pupil from the first row who seats at the third table;
  7. the pupil from the first row who seats at the first table, it means it is Sergei;
  8. the pupil from the first row who seats at the second table;

The order of asking pupils in the second test:

  1. the pupil from the first row who seats at the first table;
  2. the pupil from the first row who seats at the second table;
  3. the pupil from the second row who seats at the first table;
  4. the pupil from the second row who seats at the second table;
  5. the pupil from the third row who seats at the first table;
  6. the pupil from the third row who seats at the second table;
  7. the pupil from the fourth row who seats at the first table;
  8. the pupil from the fourth row who seats at the second table, it means it is Sergei;
  9. the pupil from the third row who seats at the first table;

思路:可以发现排是这样的1,2,3,....n, n-1,...3,2;这样是一个循环,一个循环是aa=(2×n-2)×m

那么除了1,n排是k/aa,其余的为2×k/aa,那么剩下的k%aa,再模拟下就可以了。然后在m[i][j] (模拟后每个位置上问的问题)找maxx,minn,和m[x][y];

 1 #include<bits/stdc++.h>
2 using namespace std;
3 typedef long long LL;
4 LL ma[200][200];
5 int main(void)
6 {
7 LL n,m,k,x,y;
8 scanf("%lld %lld %lld %lld %lld",&n,&m,&k,&x,&y);
9 LL ak = n*m;
10 LL maxx = 0,minn = 0;
11 LL t = 0;
12 if(n == 1)
13 {
14 int xx = 1;
15 int yy = 0;
16 maxx = k/ak;
17 minn = k/ak;
18 if(k%ak)maxx++;
19 LL ac = k%ak;
20 int d = 0;
21 LL ask = minn ;
22 if(y <= ac)
23 ask++;
24 printf("%lld %lld %lld\n",maxx,minn,ask);
25 }
26 else
27 {
28 LL acc = (2*n-2)*m;minn = k/acc;
29 if(n == 2)
30 {
31 maxx = k/acc;
32 }
33 else
34 {
35 maxx = k/acc*(LL)2;
36 }
37 for(int i = 1; i <= n; i++)
38 {
39 if(i == 1||i == n)
40 {
41 for(int j = 1; j <= m; j++)
42 {
43 ma[i][j] = minn;
44 }
45 }
46 else
47 {
48 for(int j = 1; j <= m; j++)
49 ma[i][j] = maxx;
50 }
51 }
52
53 LL low = k%acc;
54 int xx = 1;
55 int yy = 0;
56 int d = 0;
57 while(low)
58 {
59 yy++;
60 low--;
61 ma[xx][yy]++;
62 if(yy == m)
63 {
64 yy = 0;
65 if(d == 0)
66 xx++;
67 if(d == 1)
68 xx--;
69 if(xx == n+1)
70 xx = n-1,d = 1;
71 if(xx == 0)
72 xx = 2,d = 0;
73 }
74 }
75 minn = 1e16;
76 for(int i = 1; i <= n; i++)
77 {
78 for(int j = 1; j <= m; j++)
79 {
80 maxx = max(maxx,ma[i][j]);
81 minn = min(minn,ma[i][j]);
82 }
83 }
84 LL ask = ma[x][y];
85 printf("%lld %lld %lld\n",maxx,minn,ask);
86 }
87 return 0;
88 }

C. Unfair Poll的更多相关文章

  1. 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 ...

  2. 【找规律】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 ...

  3. 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 ...

  4. CodeForces 758 C Unfair Poll

    Unfair Poll 题意:一共有n排同学每排同学有m个人, 老师问问题有一个顺序, 先从第一排开始问,问完第一排的所有同学之后,再问第2排的,对于所有排的访问顺序为 1,2,3……n-1,n,n- ...

  5. CF758C Unfair Poll

    题意: On the Literature lesson Sergei noticed an awful injustice, it seems that some students are aske ...

  6. 【codeforces 758C】Unfair Poll

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. C. Unfair Poll 数学题,

    http://codeforces.com/contest/758/problem/C 需要一个能够找到任意一个位置的步数的方法,就能解决三个问题. 预处理出one(row, col)表示第一次经过这 ...

  8. Codeforces 758C:Unfair Poll(思维+模拟)

    http://codeforces.com/problemset/problem/758/C 题意:教室里有n列m排,老师上课点名从第一列第一排开始往后点,直到点到第一列第m排,就从第二列第一排开始点 ...

  9. CodeFroces 758C - Unfair Poll

    题意: 老师点名,顺序是1 -- n -- 1 排为一个循环,每列为1 -- m的顺序, 问点到最多次数和最少次数的人的次数以及(x,y)被点的次数. 分析: 由于点名有循环,故可先判断出每一个循环每 ...

随机推荐

  1. Linux—Linux系统目录结构

    登录系统后,在当前命令窗口下输入命令:  ls /  你会看到如下图所示: 树状目录结构: 以下是对这些目录的解释: /bin:bin是Binary的缩写, 这个目录存放着最经常使用的命令. /boo ...

  2. rsync实现windows和windows之间的数据同步

    一:环境 1.同步对象:测试数据 2.服务端:Windows Server 2008 R2 3.客户端:Windows7 旗舰版64位 4.服务端rsync版本:cwRsyncServer_4.1.0 ...

  3. windows系统 svn自动更新

    如果对svn不熟悉,当svn上面有更新时,想看到实时效果,就得去web目录手动更新,比较麻烦 其它svn有一个自动更新的功能 利用 hook   在svn 仓库目录下面有一个hook目录 在post- ...

  4. Spark集群环境搭建——服务器环境初始化

    Spark也是属于Hadoop生态圈的一部分,需要用到Hadoop框架里的HDFS存储和YARN调度,可以用Spark来替换MR做分布式计算引擎. 接下来,讲解一下spark集群环境的搭建部署. 一. ...

  5. 零基础学习java------26--------获取省访问量的top3,APP版本数据分析,事务,json,json字符串与对象间的相互转换,求电影平均分

    一. day23中的ip,url案例(前面答案错了) 思路分析: 1.创建javabean,用来存储ip.txt各字段的信息 2. 创建java工具类,封装相应的方法 (1) 加载读取ip.txt文档 ...

  6. Oracle中的job(定时任务)

    oracle中的job(定时任务)由dbms_job包下的函数实现.关于job的理论知识可参考https://blog.csdn.net/apextrace/article/details/77675 ...

  7. java中的collection小结

    Collection 来源于Java.util包,是非常实用常用的数据结构!!!!!字面意思就是容器.具体的继承实现关系如下图,先整体有个印象,再依次介绍各个部分的方法,注意事项,以及应用场景.   ...

  8. 编译安装haproxy2.0

    先解决lua环境,(因为centos自带的版本不符合haproxy要求的最低版本(5.3)先安装Lua依赖的包 [root@slave-master lua-5.3.5]# yum install  ...

  9. Mysql脚本 优化检测

    下载地址: wget https://launchpad.net/mysql-tuning-primer/trunk/1.6-r1/+download/tuning-primer.sh 安装依赖: y ...

  10. shell脚本 监控网卡信息

    一.简介 源码地址 日期:2018/6/22 介绍:显示实时输入输出流量 效果图: 二.使用 适用:centos6+ 语言:英文 注意:无 下载 wget https://raw.githubuser ...