Unfair Poll
来源:互联网 发布:ubuntu 优麒麟 编辑:程序博客网 时间:2024/06/06 18:03
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.
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).
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.
1 3 8 1 1
3 2 3
4 2 9 4 2
2 1 1
5 5 25 4 3
1 1 1
100 100 1000000000000000000 100 100
101010101010101 50505050505051 50505050505051
难点就是特定点的,这个地方来了个模拟,方便计算。
注意循环节,这里n<=2是一种情况,普通的循环。
当n大于2的时候,循环节变成了1....n....n-1。
#include <bits/stdc++.h>using namespace std;const int MAXN=1e5+7;long long n,m,k,x,y;int main(){ long long MAX,MIN,ans; scanf("%I64d%I64d%I64d%I64d%I64d",&n,&m,&k,&x,&y); if(n<=2||k<n*m) { long long num=n*m; MAX=MIN=k/num; if(k%num)MAX++; long long pos=(x-1)*m+y; if(pos>k%num)ans=MIN; else ans=MAX; } else { long long num=(2*n-2)*m; MIN=k/num; MAX=MIN*2; long long p=k%num; //ans long long pos=(x-1)*m+y; if(pos>p||p==0) { if(x>1&&x<n)ans=MAX; else ans=MIN; } else { if(pos>0&&pos<=m)ans=MIN+1; if(pos>m&&pos<=m*(n-1)) { if(p<=m*n)ans=MAX+1; else { long long l=pos-m; long long r=p-m*n; int t1=2,t2=n-1; while(l>m) { l-=m; t1++; } while(r>m) { r-=m; t2--; } if(t1>t2)ans=MAX+2; else if(t1==t2) { if(r>=l)ans=MAX+2; else ans=MAX+1; } else ans=MAX+1; } } else ans=MIN+1; } //MAX,MIN if(p>0&&p<=m) { } else if(p>m&&p<=m*(n-1)) { MAX++; } else if(p>m*(n-1)&&p<m*n) { MAX++; } else if(p==m*n) { MAX++; MIN++; } else if(p>m*n) { MIN++; MAX+=2; } } printf("%I64d %I64d %I64d\n",MAX,MIN,ans); return 0;}
- Unfair Poll
- Unfair Poll
- Codeforces758C Unfair Poll
- 758C - Unfair Poll
- Unfair Poll CodeForces
- Unfair Poll codeforce758 C
- 【codeforces 758C】Unfair Poll
- codeforces 392 div2 unfair poll
- Codeforces 758C-Unfair Poll
- Codeforces 758C Unfair Poll
- Codeforces 758C- Unfair Poll
- Codeforces 758C Unfair Poll 暴力模拟
- codeforces 758C - Unfair Poll 细节题
- Codeforces 758C Unfair Poll 【数学】【思维】
- CF758 C. Unfair Poll (模拟)
- 【Codeforces 758 C Unfair Poll】+ 细节
- C. Unfair Poll-数数你会不会?
- Codeforces Round #392 (Div. 2)Unfair Poll
- Eclipse中导入项目后js报错解决方法
- 2017.2.21考试总结
- css基础及css选择符
- 开博第一帖
- 二零一七一月二十一日小测试
- Unfair Poll
- 修改gmediarender对于ffmpeg的依赖库
- P2P内网穿透原理
- [C语言]除非该数组为全局变量,否则只能在定义数组时获取数组长度,在传递过程中只是传递指针不能再次获取长度
- pat-bl-1047
- Hexo搭建个人博客教程
- 微信小程序 例子
- 开源连接池比较
- shell传递参数