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 nmkx 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. 1 3 8 1 1
output
  1. 3 2 3
input
  1. 4 2 9 4 2
output
  1. 2 1 1
input
  1. 5 5 25 4 3
output
  1. 1 1 1
input
  1. 100 100 1000000000000000000 100 100
output
  1. 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……n-1,n,n-1……2,1,2这样,每排按顺序点,输入n排m列,点k次,主人公位置(x,y),问最多的人点几次,最少的人点几次,主人公点几次?

思路:博主用了最笨的方法 分类讨论,特判n=1和n=2;可惜考虑不到位终测挂了,气


  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <queue>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #include <string>
  11.  
  12. using namespace std;
  13.  
  14. int main()
  15. {
  16. long long m,n,k,x,y;
  17. while(~scanf("%I64d %I64d %I64d %I64d %I64d",&n,&m,&k,&x,&y))
  18. {
  19. if(k==m&&n==1)
  20. {
  21. printf("1 1 1\n");
  22. continue;
  23. }
  24. if(k<=m)
  25. {
  26. if(x==1&&y<=k)
  27. printf("1 0 1\n");
  28. else
  29. printf("1 0 0\n");
  30. continue;
  31. }
  32.  
  33. if(n==1)
  34. {
  35. long long ttt=k/m;
  36. long long tt=k%m;
  37. if(y<=tt)
  38. {
  39. if(tt==0)
  40. printf("%I64d %I64d %I64d\n",ttt,ttt,ttt);
  41. else
  42. printf("%I64d %I64d %I64d\n",ttt+1,ttt,ttt+1);
  43. }
  44. else
  45. {
  46. if(tt==0)
  47. printf("%I64d %I64d %I64d\n",ttt,ttt,ttt);
  48. else
  49. printf("%I64d %I64d %I64d\n",ttt+1,ttt,ttt);
  50. }
  51. continue;
  52. }
  53. if(n==2)
  54. {
  55. long long ttt=k/(m*2);
  56. long long tt=k%(m*2);
  57. long long ttc=(x-1)*m+y;
  58. if(tt==0)
  59. printf("%I64d %I64d %I64d\n",ttt,ttt,ttt);
  60. else
  61. {
  62. if(tt<ttc)
  63. printf("%I64d %I64d %I64d\n",ttt+1,ttt,ttt);
  64. else
  65. printf("%I64d %I64d %I64d\n",ttt+1,ttt,ttt+1);
  66. }
  67. continue;
  68. }
  69. k-=m;
  70. long long int cnt=k/(m*(n-1));
  71. long long int md=k%(m*(n-1));
  72. long long int zheng=(x-1)*m+y-m;
  73. long long int fan=(n-x)*m+y-m;
  74. if(cnt%2==1)
  75. {
  76. if(x==1)
  77. {
  78. if(md==0)
  79. printf("%I64d %I64d %I64d\n",cnt,cnt/2+1,cnt/2+1);
  80. else
  81. {
  82. if(fan>md)
  83. printf("%I64d %I64d %I64d\n",cnt+1,cnt/2+1,cnt/2+1);
  84. else
  85. printf("%I64d %I64d %I64d\n",cnt+1,cnt/2+1,cnt/2+2);
  86.  
  87. }
  88.  
  89. }
  90. else if(x==n)
  91. {
  92. if(md==0)
  93. printf("%I64d %I64d %I64d\n",cnt,cnt/2+1,cnt/2+1);
  94. else
  95. {
  96. printf("%I64d %I64d %I64d\n",cnt+1,cnt/2+1,cnt/2+1);
  97. }
  98. }
  99. else if(fan>md)
  100. {
  101. if(md==0)
  102. printf("%I64d %I64d %I64d\n",cnt,cnt/2+1,cnt);
  103. else
  104. printf("%I64d %I64d %I64d\n",cnt+1,cnt/2+1,cnt);
  105. }
  106. else
  107. {
  108. printf("%I64d %I64d %I64d\n",cnt+1,cnt/2+1,cnt+1);
  109. }
  110. }
  111. else
  112. {
  113. if(x==1)
  114. {
  115. if(md==0)
  116. printf("%I64d %I64d %I64d\n",cnt,cnt/2,cnt/2+1);
  117. else
  118. {
  119. printf("%I64d %I64d %I64d\n",cnt+1,cnt/2,cnt/2+1);
  120. }
  121.  
  122. }
  123. else if(x==n)
  124. {
  125. if(md==0)
  126. printf("%I64d %I64d %I64d\n",cnt,cnt/2,cnt/2);
  127. else
  128. {
  129. if(zheng>md)
  130. printf("%I64d %I64d %I64d\n",cnt+1,cnt/2,cnt/2);
  131. else
  132. printf("%I64d %I64d %I64d\n",cnt+1,cnt/2,cnt/2+1);
  133. }
  134. }
  135. else if(zheng>md)
  136. {
  137. if(md==0)
  138. printf("%I64d %I64d %I64d\n",cnt,cnt/2,cnt);
  139. else
  140. printf("%I64d %I64d %I64d\n",cnt+1,cnt/2,cnt);
  141. }
  142. else
  143. {
  144. printf("%I64d %I64d %I64d\n",cnt+1,cnt/2,cnt+1);
  145. }
  146. }
  147.  
  148. }
  149.  
  150. return 0;
  151. }

Codeforces758C Unfair Poll 2017-01-20 10:24 95人阅读 评论(0) 收藏的更多相关文章

  1. 菜鸟学习-C语言函数参数传递详解-结构体与数组 分类: C/C++ Nginx 2015-07-14 10:24 89人阅读 评论(0) 收藏

    C语言中结构体作为函数参数,有两种方式:传值和传址. 1.传值时结构体参数会被拷贝一份,在函数体内修改结构体参数成员的值实际上是修改调用参数的一个临时拷贝的成员的值,这不会影响到调用参数.在这种情况下 ...

  2. config 数据库字符串的读取、修改 分类: WebForm 2014-12-16 10:24 203人阅读 评论(0) 收藏

    config数据库字符串: <connectionStrings>   <add name="MyWebDataString" connectionString= ...

  3. 博弈论入门小结 分类: ACM TYPE 2014-08-31 10:15 73人阅读 评论(0) 收藏

    文章原地址:http://blog.csdn.net/zhangxiang0125/article/details/6174639 博弈论:是二人或多人在平等的对局中各自利用对方的策略变换自己的对抗策 ...

  4. C语言基础总结 分类: iOS学习 c语言基础 2015-06-11 10:08 23人阅读 评论(0) 收藏

    //欲练此功必先自宫!!!     //第一天:C语言的基础     //进制     //2进制, 10进制, 8进制, 16进制     //注:8进制数前加0, 16进制数前加0x        ...

  5. DNA Sorting 分类: POJ 2015-06-23 20:24 9人阅读 评论(0) 收藏

    DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 88690 Accepted: 35644 Descrip ...

  6. 【C#小知识】C#中一些易混淆概念总结(二)--------构造函数,this关键字,部分类,枚举 分类: C# 2014-02-03 01:24 1576人阅读 评论(0) 收藏

    目录: [C#小知识]C#中一些易混淆概念总结--------数据类型存储位置,方法调用,out和ref参数的使用 继上篇对一些C#概念问题进行细节的剖析以后,收获颇多.以前,读书的时候,一句话一掠而 ...

  7. winform timespan 两个时间的间隔(差) 分类: WinForm 2014-04-15 10:14 419人阅读 评论(0) 收藏

    TimeSpan 结构  表示一个时间间隔. 先举一个小例子:(计算两个日期相差的天数) 代码如下: DateTime dt = DateTime.Now.ToShortDateString(yyyy ...

  8. 全面解析sizeof(上) 分类: C/C++ StudyNotes 2015-06-15 10:18 188人阅读 评论(0) 收藏

    以下代码使用平台是Windows7 64bits+VS2012. sizeof是C/C++中的一个操作符(operator),其作用就是返回一个对象或者类型所占的内存字节数,使用频繁,有必须对齐有个全 ...

  9. Financial Management 分类: POJ 2015-06-11 10:51 12人阅读 评论(0) 收藏

    Financial Management Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 164431   Accepted: ...

随机推荐

  1. GNU Radio: 射频子板

    本文简要介绍 USRP 配套的子板参数信息. 射频子板WBX-40 性能特点 频率覆盖:50 MHz – 2.2GHz 最大信号处理带宽:40MHz 行为描述 WBX-40提供高宽带收发器,可提供高达 ...

  2. SQL Server 查询表的主键的两种方式

    方式1: select b.column_name from information_schema.table_constraints a inner join information_schema. ...

  3. Erlang tool -- recon

    遇见recon 以来, 每次定位系统瓶颈, 总是能让我眼前一亮. 比如说, 定位非尾递归导致的内存暴涨, 定位引发CPU满载的进程.得心应手,每每额手称庆. recon 是ferd 大神 释出的一个 ...

  4. 腾讯EC .net API对接第三方系统

    最近公司销售部门用到了腾讯EC,实现公司内部OA系统与腾讯ec的数据同步,要求如下: 1.OA内部系统账号与腾讯ec登陆账号同步 2.首先做义工客户端工具用来把现有客户导入到EC,销售人员的客户信息与 ...

  5. C#操作 iis启用父目录

    iis6实现: DirectoryEntry site = (DirectoryEntry)root.Invoke("Create", "IIsWebServer&quo ...

  6. redis与lua

    内容大纲 redis里使用eval和evalsha redis管理Lua脚本  php里使用redis的lua脚本 在redis里使用lua脚本的好处 1.Lua脚本在Redis中是原子执行的,执行过 ...

  7. NP、NPC、NP-hard问题的定义

    NP-hard问题    定义:NP-hard问题是这样的问题,只要其中某个问题可以在P时间内解决,那么所有的NP问题就都可以在P时间内解决了.NP-c问题就是NP-hard问题.但注意NP-hard ...

  8. mysql修复表

    数据库Table xxx is marked as crashed and should be repaired错误的解决方法服务器断电等原因可能导致数据表损坏,导致访问的时候提示:Table xxx ...

  9. 20165233 Java第四章学习总结

    20165233 2017-2018-2 <Java程序设计>第三周学习总结 教材学习内容总结 基础 类:包括类声明和类体. 其中类声明的变量被称作对象变量,简称对象. 类体中包括两部分: ...

  10. SQL 基础命令和函数

    [数据操作] SELECT --从数据库表中检索数据行和列 INSERT --向数据库表添加新数据行 DELETE --从数据库表中删除数据行 UPDATE --更新数据库表中的数据 [数据定义] C ...