Codeforces Round #392 (Div. 2)C. Unfair Poll(找循环节)
2017-01-27 21:57
471 查看
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 n, m, k, x 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的教室中,老师一共提问k次。提问的方式为行:1–n–1,列:1-m。问最多被提问的次数和最少被提问的次数和坐在【x,y】的同学被提问的次数。
题解:
因为k特别大。o(k)模拟肯定不行,想到这一定存在循环节的。对于x,y来说,行的周期为2*(n-1),列的周期为m。则周期为T=2*(n-1)*m(显然要判断n>1然后模拟余数即可。
代码:
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 n, m, k, x 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的教室中,老师一共提问k次。提问的方式为行:1–n–1,列:1-m。问最多被提问的次数和最少被提问的次数和坐在【x,y】的同学被提问的次数。
题解:
因为k特别大。o(k)模拟肯定不行,想到这一定存在循环节的。对于x,y来说,行的周期为2*(n-1),列的周期为m。则周期为T=2*(n-1)*m(显然要判断n>1然后模拟余数即可。
代码:
#include<stdio.h> #include<string.h> #include<iostream> #include<vector> #include<algorithm> #define ll long long using namespace std; ll a[105][105]; int n,m,x,y; ll k; int main() { memset(a,0,sizeof(a)); cin>>n>>m>>k>>x>>y; ll T=n>1?2*m*(n-1):m; for(int j=1;j<=m;j++) { a[1][j]=a [j]=k/T; } for(int i=2;i<n;i++) { for(int j=1;j<=m;j++) { a[i][j]=k/T*2; } } int sum=0; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(sum<k%T) { sum++; a[i][j]++; } } } for(int i=n-1;i>1;i--) { for(int j=1;j<=m;j++) { if(sum<k%T) { sum++; a[i][j]++; } } } ll mi=1e19; ll mx=-1; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { mi=min(mi,a[i][j]); mx=max(mx,a[i][j]); } } cout<<mx<<" "<<mi<<" "<<a[x][y]<<endl; return 0; }
相关文章推荐
- Codeforces Round #392 (Div. 2) C - Unfair Poll codeforces
- Codeforces Round #392 (Div. 2)-C. Unfair Poll(xjb)
- Codeforces Round #392 (Div. 2)Unfair Poll
- Codeforces Round #392 (Div. 2) C && 758C Unfair Poll(模拟)
- Codeforces Round #392(Div. 2) C Unfair Poll【思维+暴力】
- Unfair Poll (模拟)
- 【CodeForces - 758C Unfair Poll】 暴力 + 模拟
- Codeforces Round #334 (Div. 2) D(数论 循环节)
- C. Unfair Poll-数数你会不会?
- Codeforces Round #260 (Div. 2)456B - Fedya and Maths (找循环节,大数取模)那些用int的人运气真好,竟然没人去Hack
- 【Codeforces Round 323 (Div 2)D】【暴力 脑洞 插入贡献思想】Once Again... 循环节重复T次后的LIS
- Codeforces Round #305 (Div. 2)C. Mike and Frog 数学(循环节)
- Codeforces Round #362 (Div. 1) C PLEASE(组合数学,指数循环节)
- C. Unfair Poll
- Codeforces Round #260 (Div. 2) B. Fedya and Maths(循环节)
- 【循环节】 Codeforces Round #401 (Div. 2) A. Shell Game
- Codeforces Round #334 (Div. 2) D(数论 循环节)
- Unfair Poll codeforce758 C
- Codeforces Round #257 (Div. 2) 450B - Jzzhu and Sequences(循环节或矩阵快速幂)
- Codeforces 547 Div1 A. Mike and Frog(找循环节)