CF758C Unfair Poll

题意:

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

思路:

模拟。

实现:

 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 typedef long long ll;
 5 ll n, m, k, x, y, maxn, minn, t;
 6 int main()
 7 {
 8     cin >> n >> m >> k >> x >> y;
 9     if (n == 1)
10     {
11         maxn = k / m + (k % m ? 1 : 0);
12         minn = k / m;
13         t = y > k % m ? minn : maxn;
14         cout << maxn << " " << minn << " " << t << endl;
15     }
16     else
17     {
18         ll t = (2 * n - 2) * m;
19         ll tmp = k / t;
20         ll rem = k % t;
21         maxn = n > 2 ? 2 * tmp : tmp, minn = tmp;
22         t = (x == 1 || x == n) ? minn : maxn;
23         if (rem)
24         {
25             if (rem > n * m)
26             {
27                 maxn += 2;
28                 minn++;
29                 ll p = (rem - n * m) / m;
30                 ll q = (rem - n * m) % m;
31                 ll nx = n - 1 - p;
32                 ll ny = q;
33                 if (ny == 0)
34                 {
35                     nx++;
36                     ny = m;
37                 }
38                 if (x < nx || x == nx && y > ny || x == n)
39                 {
40                     t++;
41                 }
42                 else
43                 {
44                     t += 2;
45                 }
46             }
47             else if (rem == n * m)
48             {
49                 maxn++;
50                 minn++;
51                 t++;
52             }
53             else
54             {
55                 if (rem > m)
56                     maxn++;
57                 else if (maxn == minn)
58                     maxn++;
59                 ll nx = rem / m;
60                 ll ny = rem % m;
61                 if (ny)
62                 {
63                     nx++;
64                 }
65                 else
66                 {
67                     ny = m;
68                 }
69                 if (!(x > nx || x == nx && y > ny))
70                 {
71                     t++;
72                 }
73             }
74         }
75         cout << maxn << " " << minn << " " << t << endl;
76     }
77     return 0;
78 }
时间: 2024-10-26 02:44:05

CF758C Unfair Poll的相关文章

CodeForces 758 C Unfair Poll

Unfair Poll 题意:一共有n排同学每排同学有m个人, 老师问问题有一个顺序, 先从第一排开始问,问完第一排的所有同学之后,再问第2排的,对于所有排的访问顺序为 1,2,3--n-1,n,n-1,n-2,--,2,1,2,然后每次访问到新的一排先要问完这一排的所有人才会往下一(目标)排走. 题解:先声明我们开一个数组来记录这一排被询问的总次数,先将k  /= m, 这个代表的是完全访问的次数,即一整排m位同学都问完有几次,如果  完全访问的次数< n, 我们就将前几排全访问次数的人都加上

Codeforces 392 C Unfair Poll(模拟)

题意:老师点名顺序规则如下:第1排,第2排,--,第n-1排,第n排,第n-1排,--,第2排,第1排,第2排,--,第n-1排,第n排,--对于每排都是从左到右依次点名,问点名k个人后,所有人中最多的点名次数,最少的点名次数,以及位于x排y列处的同学的点名次数. 分析: 1.由于k很大,将第1排,第2排,--,第n-1排,第n排,第n-1排,--,第2排看成一个循环. 2.这个循环中有2*(n-1)*m个人,注意当n=1时,这个循环中有m个人,将这个循环人数记为tmp. 3.利用k/tmp,算

CodeFroces 758C - Unfair Poll

题意: 老师点名,顺序是1 -- n -- 1 排为一个循环,每列为1 -- m的顺序, 问点到最多次数和最少次数的人的次数以及(x,y)被点的次数. 分析: 由于点名有循环,故可先判断出每一个循环每个人被点名的次数,再乘以循环数,为答案一部分. 最后一个循环结束后k还有余数,从(1,1)暴力模拟,因为n*m才10000, 再加上前面的,就能得出答案. 注意 n=1 需要特判. 1 #include <bits/stdc++.h> 2 using namespace std; 3 #defin

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

http://codeforces.com/problemset/problem/758/C 题意:教室里有n列m排,老师上课点名从第一列第一排开始往后点,直到点到第一列第m排,就从第二列第一排开始点,当点完第n列的名之后,接着点第n-1列的名.以此类推,就是从列上来看的话:1,2,3,4,……,n,n-1,n-2,……,1 ,2,…….这样的顺序点名.老师上课总共点k次名,问该课堂最多可以点同一个同学多少次,最少可以点同一个同学多少次,点了位置为(x,y)的同学多少次名. 思路:一遇到这种题目

Codeforces Round #392 (Div. 2)

A - Holiday Of Equality(water) 题意:一共给你N个数,让你向上补数值,使得最终所有数值都相等,输出最少花费. 1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 const int INF = 0x3f3f3f3f; 5 const int maxn = 100 + 5; 6 7 int a[maxn]; 8 9 int main() 10 { 11 int n;

CF #392(2) C 暴力模拟

CF #392(2)  C. Unfair Poll 题意:n行m列人,老师点k次名.点名次序,每一行都是从1到m,但行是按1,2....(n-1),n,(n-1),(n-2)...1,2,3....(n-1),n.....求点完k次名后被点的最多的次数和最少的次数,以及给定的(x,y)被点次数. 总结:有点麻烦,但还是很好找规律,只是fst了,有时间再写一遍...还是太菜了,连着三场CF都是fst #include<bits/stdc++.h> using namespace std; #p

codeforces 758C

codeforces 758C C. Unfair Poll introduction 一个矩形方格,从前到后,再从后到前数k次,问每个方格最多/最少经过多少次,(x,y)方格上经过多少次 method 遍历是有周期的,一个周期经过2(n-1)m个方格,当n=1时,周期为m 先求出周期,再求出剩下的次数,然后将剩下的次数,通过遍历分配到每一个方格上 tips o(1)解决问题比较困难的时候,可以向o(n)求助 Q&A conclusion 想到了周期性,但是没有处理好外层循环和内层循环的关系,

I/O多路转接 &#160; ---- &#160; poll

一.poll poll的实现和select非常相似,只是描述fd集合的方式不同,poll使用pollfd结构而不是select的fd_set结构,其他的都差不多. 二.poll相关函数 #include <poll.h> int poll(struct pollfd *fds, nfds_t nfds, int timeout); //fds: pollfd结构体 events: 要监视的事件 revents: 已经发生的事件,  设置标志 来反映相关条件的存在 常量            

多路复用之select、epoll、poll

IO的多路复用:一个进程可以监视多个描述符,一旦某个描述符读就绪或写就绪,能够通知进程程序进行相应的读写操作 使用场景: 1.当客户处理多个描述符(网络套接口)或一个客户同时处理多个套接口 2.TCP服务器既要处理监听套接口又要处理已经连接的套接口 3.一个服务器处理多个服务或多个协议也要使用I/O复用 与多进程和多线程相比,I/O多路复用最大优点系统开销小,系统也不必创建进程或线程,因而也不用维护这些进程和线程 支持I/O多路复用的系统调用:select.poll.epoll本质上都是同步IO