Codeforces Round #392 (Div. 2)C. Unfair Poll
2017-01-29 21:22
330 查看
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;
找规律,纯公式计算感觉太麻烦,对于重复部分计算,多出来的那一小部分开个数组模拟一下就行了
举个例子
n=4时
1 2 3 4 3 2 1 2 3 4 3 2
所以重复的部分就是1 2 3 4 3 2
1 2 ..n-1 n n-1 ...2
2*n-2行,其中每重复一次,第1行和第n行上的被提问一次,其余行上的被提问两次
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
using namespace std;
int main()
{
long long int t,k,n,m,x,y,maxx,minn,ans;
maxx=0;
minn=0x3f3f3f3f3f3f3f3f;
int i,j,book[200][200];
memset(book,0,sizeof(book));
scanf("%lld %lld %lld %lld %lld",&n,&m,&k,&x,&y);
if(n==1)
{
t=k/m;
k%=m;
}
else
{
t=k/((2*n-2)*m);
k%=((2*n-2)*m);
}
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(!k)
break;
book[i][j]++;
k--;
}
if(!k)
break;
}
for(i=n-1;i>=2;i--)
{
for(j=1;j<=m;j++)
{
if(!k)
break;
book[i][j]++;
k--;
}
if(!k)
break;
}
if(x==1||x==n)
ans=t+book[x][y];
else
ans=2*t+book[x][y];
for(i=1;i<=m;i++)
{
minn=min(minn,t+book[1][i]);
minn=min(minn,t+book
[i]);
maxx=max(maxx,t+book[1][i]);
maxx=max(maxx,t+book
[i]);
}
for(i=2;i<=n-1;i++)
{
for(j=1;j<=m;j++)
{
minn=min(minn,2*t+book[i][j]);
minn=min(minn,2*t+book[i][j]);
maxx=max(maxx,2*t+book[i][j]);
maxx=max(maxx,2*t+book[i][j]);
}
}
printf("%lld %lld %lld\n",maxx,minn,ans);
return 0;
}
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;
找规律,纯公式计算感觉太麻烦,对于重复部分计算,多出来的那一小部分开个数组模拟一下就行了
举个例子
n=4时
1 2 3 4 3 2 1 2 3 4 3 2
所以重复的部分就是1 2 3 4 3 2
1 2 ..n-1 n n-1 ...2
2*n-2行,其中每重复一次,第1行和第n行上的被提问一次,其余行上的被提问两次
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
using namespace std;
int main()
{
long long int t,k,n,m,x,y,maxx,minn,ans;
maxx=0;
minn=0x3f3f3f3f3f3f3f3f;
int i,j,book[200][200];
memset(book,0,sizeof(book));
scanf("%lld %lld %lld %lld %lld",&n,&m,&k,&x,&y);
if(n==1)
{
t=k/m;
k%=m;
}
else
{
t=k/((2*n-2)*m);
k%=((2*n-2)*m);
}
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(!k)
break;
book[i][j]++;
k--;
}
if(!k)
break;
}
for(i=n-1;i>=2;i--)
{
for(j=1;j<=m;j++)
{
if(!k)
break;
book[i][j]++;
k--;
}
if(!k)
break;
}
if(x==1||x==n)
ans=t+book[x][y];
else
ans=2*t+book[x][y];
for(i=1;i<=m;i++)
{
minn=min(minn,t+book[1][i]);
minn=min(minn,t+book
[i]);
maxx=max(maxx,t+book[1][i]);
maxx=max(maxx,t+book
[i]);
}
for(i=2;i<=n-1;i++)
{
for(j=1;j<=m;j++)
{
minn=min(minn,2*t+book[i][j]);
minn=min(minn,2*t+book[i][j]);
maxx=max(maxx,2*t+book[i][j]);
maxx=max(maxx,2*t+book[i][j]);
}
}
printf("%lld %lld %lld\n",maxx,minn,ans);
return 0;
}
相关文章推荐
- Codeforces Round #392 (Div. 2)C Unfair Poll
- codeforces 392 div2 unfair poll
- 【找规律】Codeforces Round #392 (Div. 2) C. Unfair Poll
- DIV居中的CSS
- 以div代替frameset,用css实现仿框架布局
- poj 1845 Sumdiv
- Codeforces Round #254 (Div. 2) __B. DZY Loves Chemistry
- 固定滚动外层div的css
- div+css页面布局-html代码
- codeforces水题100道 第十四题 Codeforces Round #321 (Div. 2) A. Kefa and First Steps (brute force)
- Codeforces Round #390 (Div. 2)D Fedor and coupons
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
- DIV+CSS页面布局——页面居中
- 键盘控制div移动
- SRM 585 DIV1 L2
- JS指定时间自动关闭一个基于DIV的层提示框代码
- C. Glass Carving (CF Round #296 (Div. 2) STL--set的运用 && 并查集方法)
- DIV滚动条到底部判断且自动加载,到上限更多选项
- Codeforces Round #315 (Div. 2) C. Primes or Palindromes? 暴力
- 【置换群】Codeforces Round #393 (Div. 1) A. Pavel and barbecue