Unfair Poll CodeForces
来源:互联网 发布:牛贝 微信淘宝客 编辑:程序博客网 时间:2024/06/05 20:10
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 withm 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: the1-st row, the 2-nd row,..., the n - 1-st row, then-th row, the n - 1-st row,..., the 2-nd row, the1-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 thex-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
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;
细节题,感觉自己就是改练这种题,我一般这种题,直接废掉,由于情况是在是太多。
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;typedef long long ll;const ll INF=1e18;/*这道题WA了一万遍,简直吐血了,要不是看着测试数据,感觉指定就废了但是还是想把自己的思路实现,发现真的很麻烦,想着能够一步到位可是需要考虑的情况实在是太多,就是这个细节的问题,我不愿意写长代码因为我怕忘了,自己的脑子,一看代码量十分大的话,就很痛苦,逻辑直接就乱了,这个代码大改三遍,小改了无数遍还是思路得到,不能一想就是了,我们要把极端想进来,自己构造测试数据,自己心里有底了,我们再去提交代码,不要自己心里都没有底,就去提交,白白的WA,很是痛苦啊还有就是看见有人用二维数组模拟,感觉那个应该会更简单*/ll num[110];int main(){ ll n,m,x,y; ll k; scanf("%I64d %I64d %I64d %I64d %I64d",&n,&m,&k,&x,&y); ll ans_max=0,ans_min=INF; ll ans_peo; if(n==1) { ll ans_time=k/m; ll ans_rest=k%m; ans_max=ans_min=ans_peo=ans_time; if(ans_rest) { if(y<=ans_rest) ans_peo=ans_time+1; ans_max++; } } else if(k<m) { if(k==0) ans_max=ans_min=ans_peo=0; else { ans_max=1;ans_min=ans_peo=0; if(y<=k&&x==1) ans_peo=1; } } else { ll one_time=(n-1)*m; ll ans_time=(k-m)/one_time; ll ans_rest=(k-m)%one_time; for(int i=2;i<=n-1;i++) { num[i]=ans_time; } if(ans_time&1) { num[1]= num[n]=(ans_time+1)/2; ans_max=max(ans_max,num[n]); ans_min=min(ans_min,num[n]); int i; int flag=0; for(i=n-1;i>=1;) { if(ans_rest>=m) { ans_rest-=m; num[i]++; } else if(ans_rest==0) { ans_max=max(ans_max,num[i]); ans_min=min(ans_min,num[i]); break; } else if(ans_rest>0) { num[i]++; if(x==i&&y<=ans_rest) { ans_peo=num[i]; flag=1; } else if(x==i&&y>ans_rest) { ans_peo=num[i]-1; flag=1; } ans_max=max(ans_max,num[i]); ans_min=min(ans_min,num[i]-1); i++; break; } ans_max=max(ans_max,num[i]); ans_min=min(ans_min,num[i]); i--; } for(int j=i-1;j>=1;j--) { ans_max=max(ans_max,num[i]); ans_min=min(ans_min,num[i]); } if(!flag) ans_peo=num[x]; } else { num[n]=num[1]=ans_time/2; num[1]++; //printf("num:%I64d\n",num[1]); ans_max=max(ans_max,num[1]); ans_min=min(ans_min,num[n]); int i; int flag=0; for(i=2;i<=n;) { if(ans_rest>=m) { ans_rest-=m; num[i]++; } else if(ans_rest==0) { ans_max=max(ans_max,num[i]); ans_min=min(ans_min,num[i]); break; } else if(ans_rest>0) { num[i]++; if(x==i&&y<=ans_rest) { ans_peo=num[i]; flag=1; } else if(x==i&&y>ans_rest) { ans_peo=num[i]-1; flag=1; } ans_max=max(ans_max,num[i]); ans_min=min(ans_min,num[i]-1); break; } ans_max=max(ans_max,num[i]); ans_min=min(ans_min,num[i]); i++; } for(int j=i+1;j<=n;j++) { ans_max=max(ans_max,num[i]); ans_min=min(ans_min,num[i]); } if(!flag) ans_peo=num[x]; } } printf("%I64d %I64d %I64d\n",ans_max,ans_min,ans_peo); return 0;}
- Unfair Poll CodeForces
- 【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 【数学】【思维】
- 【Codeforces 758 C Unfair Poll】+ 细节
- Codeforces Round #392 (Div. 2)Unfair Poll
- CodeForces 758C Unfair Poll(模拟)
- Unfair Poll
- Unfair Poll
- Codeforces Round #392 (Div. 2) C - Unfair Poll codeforces
- Codeforces Round #392 (Div. 2) C. Unfair Poll
- Codeforces Round #392 (Div. 2)-C. Unfair Poll(xjb)
- Codeforces Round #392(Div. 2) C Unfair Poll【思维+暴力】
- 如何实现Linux进程之间的通信?
- SQL注入-攻入Apple ID钓鱼网站实录
- Python笔记(十二)--循环控制语句
- Myeclipse快捷键大全
- 对于c/c++中char型可以输入整型,而int型却不能输入字符
- Unfair Poll CodeForces
- 范式的理解
- JAVA-JVM参数
- 0<0x80000000与0x80000000是32位有符号整型最小值的随记
- 权利的游戏-第七季第七集
- nuttx-smartfs
- Spark-Sql启动报错:Error creating transactional connection factory
- [Java] 静态方法与非静态方法的区别
- java数组发牌