【找规律】Codeforces Round #392 (Div. 2) C. Unfair Poll
2017-01-20 02:08
459 查看
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;
假设老师从第一行叫到最后一行或者从最后一行叫到第一行是一轮,可以得到式子m(nq-q+1)<=k,由此可以推出q(轮数)的最大值。
剩余的叫的次数就可以暴力了。
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;
假设老师从第一行叫到最后一行或者从最后一行叫到第一行是一轮,可以得到式子m(nq-q+1)<=k,由此可以推出q(轮数)的最大值。
剩余的叫的次数就可以暴力了。
#include<cstdio> #include<algorithm> using namespace std; typedef long long ll; ll K; int n,m,x,y; ll ci[110]; int a[110][110]; int main() { // freopen("c.in","r",stdin); scanf("%d%d%I64d%d%d",&n,&m,&K,&x,&y); if(n==1) { if(K%(ll)m==0) printf("%I64d %I64d %I64d\n",K/(ll)m,K/(ll)m,K/(ll)m); else printf("%I64d %I64d %I64d\n",K/(ll)m+1ll,K/(ll)m,(ll)y<=K%(ll)m ? K/(ll)m+1ll : K/(ll)m); return 0; } ll q=(K-(ll)m)/(ll)(m*(n-1)); ll _n=q/2ll; ll _1=(q-1)/2ll; for(int i=2;i<n;++i) ci[i]=q; ci[1]=q-_1; ci =q-_n; int nowx; if(q%2==1) nowx=n-1; else nowx=2; int nowy=1; bool flag; if(q%2==1) flag=1; else flag=0; if(q==0) nowx=1; for(ll i=(q==0 ? 1ll : (ll)m*((ll)n*q-q+1ll)+1ll);i<=K;++i) { ++a[nowx][nowy]; if(nowy!=m) ++nowy; else { nowy=1; if(nowx==n) { nowx=n-1; flag=1; } else if(nowx==1) { nowx=2; flag=0; } else { if(flag) --nowx; else ++nowx; } } } ll maxv=0,minv=1000000000000000001ll; for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) { maxv=max(maxv,ci[i]+(ll)a[i][j]); minv=min(minv,ci[i]+(ll)a[i][j]); } printf("%I64d %I64d %I64d\n",maxv,minv,ci[x]+(ll)a[x][y]); return 0; }
相关文章推荐
- HDU 5597 GTW likes function(规律+欧拉函数模板题)——BestCoder Round #66(div.1 div.2)
- Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)(B)(构造,找规律)
- Codeforces Round #419 (Div. 2) D - Karen and Test(规律 杨辉三角)
- 【博弈论】【SG函数】【找规律】Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) E. Game of Stones
- Codeforces Round #327 (Div. 2) (C. Median Smoothing 找规律)
- Codeforces Round #468 (Div. 2) D. Peculiar apple-tree(找规律)
- Codeforces Round #209 (Div. 2) Problem A Table(找规律)
- Codeforces Round #264 (Div. 2)C(找规律)
- Codeforces Round #435 (Div. 2)-异或规律&思维-Mahmoud and Ehab and the xor
- Codeforces Round #272 (Div. 2) D. Dreamoon and Sets (思维 数学 规律)
- Codeforces #275 (Div. 2)(数学:找规律)
- CF#277 (Div. 2) A.(找规律)
- Codeforces Round #368 (Div. 2)(C. Pythagorean Triples 勾股数规律)
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) D. Sorting the Coins【规律】
- Codeforces Round #419 (Div. 2) D - Karen and Test(规律 杨辉三角)
- Codeforces Round #328 (Div. 2) B. The Monster and the Squirrel (规律)
- Codeforces - 337C(div2) - Harmony Analysis【规律】
- Codeforces Round #411 (Div. 2) D 规律题
- codeforces round#366(div2) A(暴力)B(博弈 找规律)C(模拟 队列)
- Codeforces Round #419 (Div. 2) D - Karen and Test(规律 杨辉三角)