Codeforces 758C Unfair Poll 数学推导,公式

来源:互联网 发布:阿玛尼没有入住淘宝吗 编辑:程序博客网 时间:2024/05/19 22:49

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


一个n*m的方阵,依次点名,顺序为先行后列,每一行顺序为1,2,3...m,行数顺序为1,2,...n-1,n,n-1,...2,1,2....

求点了k次后,最多、最少被点多少次,以及坐标(x,y)的人被点多少次。


直接根据条件推公式。

要特别注意n=2时的最小值!!!!

被坑的太惨了,浪费了一个多小时,泪。。。


#include <cstdio>#include <iostream>#include <string.h>#include <string> #include <map>#include <queue>#include <vector>#include <set>#include <algorithm>#include <math.h>#include <cmath>#include <bitset>#define mem0(a) memset(a,0,sizeof(a))#define meminf(a) memset(a,0x3f,sizeof(a))using namespace std;typedef long long ll;typedef long double ld;const int maxn=10555,inf=0x3f3f3f3f;const ll llinf=0x3f3f3f3f3f3f3f3f; const ld pi=acos(-1.0L);int main() {//freopen("input.txt","r",stdin);//freopen("output.txt","w",stdout);ll n,m;ll x,y;ll k;while (scanf("%I64d%I64d%I64d%I64d%I64d",&n,&m,&k,&x,&y)!=EOF) {ll ans;if (n==1) {if (k<=m) ans=1; else ans=(k-1)/m+1;printf("%I64d ",ans);ans=k/m;printf("%I64d ",ans);if (k<y) ans=0; else ans=(k-y)/m+1;printf("%I64d\n",ans);continue;}if (n==2) ans=(k-1)/(m*2)+1; elseif (k<=n*m) ans=1; else {ans=(k-1-n*m)/((n-1)*m)+2;}printf("%I64d ",ans);if (k<n*m) ans=0; else {ans=(k-n*m)/(2*(n-1)*m)+1;}printf("%I64d ",ans);if (x==n) {    if (k<y+(n-1)*m) ans=0; else     ans=(k-y-(n-1)*m)/(2*(n-1)*m)+1;} else if (x==1) {if (k<y) ans=0; else     ans=(k-y)/(2*(n-1)*m)+1;} else {ll u=k/((n-1)*m);k=k-u*(n-1)*m;if (u%2) {if (k>=(n-x)*m+y) ans=u+1; else ans=u;} else {if (k>=(x-1)*m+y) ans=u+1; else ans=u;}}printf("%I64d\n",ans);}return 0;}


原创粉丝点击