C. Unfair Poll
2017-01-20 23:54
344 查看
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:
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.
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:
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.
Examples
Input
Output
Input
Output
Input
Output
Input
Output
Note
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;
思路:可以发现排是这样的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];
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:
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.
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:
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.
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:
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;
思路:可以发现排是这样的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];
#include<bits/stdc++.h> using namespace std; typedef long long LL; LL ma[200][200]; int main(void) { LL n,m,k,x,y; scanf("%lld %lld %lld %lld %lld",&n,&m,&k,&x,&y); LL ak = n*m; LL maxx = 0,minn = 0; LL t = 0; if(n == 1) { int xx = 1; int yy = 0; maxx = k/ak; minn = k/ak; if(k%ak)maxx++; LL ac = k%ak; int d = 0; LL ask = minn ; if(y <= ac) ask++; printf("%lld %lld %lld\n",maxx,minn,ask); } else { LL acc = (2*n-2)*m;minn = k/acc; if(n == 2) { maxx = k/acc; } else { maxx = k/acc*(LL)2; } for(int i = 1; i <= n; i++) { if(i == 1||i == n) { for(int j = 1; j <= m; j++) { ma[i][j] = minn; } } else { for(int j = 1; j <= m; j++) ma[i][j] = maxx; } } LL low = k%acc; int xx = 1; int yy = 0; int d = 0; while(low) { yy++; low--; ma[xx][yy]++; if(yy == m) { yy = 0; if(d == 0) xx++; if(d == 1) xx--; if(xx == n+1) xx = n-1,d = 1; if(xx == 0) xx = 2,d = 0; } } minn = 1e16; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { maxx = max(maxx,ma[i][j]); minn = min(minn,ma[i][j]); } } LL ask = ma[x][y]; printf("%lld %lld %lld\n",maxx,minn,ask); } return 0; }
相关文章推荐
- CF758 C. Unfair Poll (模拟)
- C. Unfair Poll-数数你会不会?
- 【Codeforces 758 C Unfair Poll】+ 细节
- Codeforces Round #392 (Div. 2) C && 758C Unfair Poll(模拟)
- Codeforces Round #392 (Div. 2)Unfair Poll
- Codeforces 758C Unfair Poll 数学推导,公式
- CF758 C. Unfair Poll (模拟)
- 【CodeForces - 758C Unfair Poll】 暴力 + 模拟
- C. Unfair Poll 数学题,
- CodeForces 758C Unfair Poll(模拟)
- Codeforces Round #392 (Div. 2) C - Unfair Poll codeforces
- Unfair Poll CodeForces - 758C
- Unfair Poll (模拟)
- Codeforces Round #392 (Div. 2)-C. Unfair Poll(xjb)
- Codeforces Round #392 (Div. 2)C. Unfair Poll(找循环节)
- Codeforces Round #392(Div. 2) C Unfair Poll【思维+暴力】
- Codeforces 758C Unfair Poll 【数学】【思维】
- Unfair Poll codeforce758 C
- PollVote投票系统漏洞利用
- ACE_Dev_Poll_Reactor的处理优先级严重偏向定时器