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 nmkx 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;

思路:一个稍微麻烦一点的模拟..

思路清晰的代码:

 #include <iostream>
using namespace std;
typedef long long ll;
ll n,m,k,x,y,mx,mn;
ll f(ll x, ll y, ll k)
{
ll ans=;
if(n==)
{
ans=k/m;
k-=ans*m;
if(k>=y)
ans++;
}
else if(x==)
{
ll cnt=k/((n-)*m);
k-=cnt*(n-)*m;
ans+=(cnt+)/;
if(cnt&)
{
for(ll i=n;k>&&i>=;i--,k-=m)
if(i==x&&k>=y)
ans++;
}
else
{
for(ll i=;i<=n&&k>;i++,k-=m)
if(i==x&&k>=y)
ans++;
}
}
else if(x==n)
{
ll cnt=k/((n-)*m);
k-=cnt*(n-)*m;
ans+=cnt/;
if(cnt&)
{
for(ll i=n;k>&&i>=;i--,k-=m)
if(i==x&&k>=y)
ans++;
}
else
{
for(ll i=;i<=n&&k>;i++,k-=m)
if(i==x&&k>=y)
ans++;
}
}
else
{
ans+=k/((n-)*m);
k-=ans*(n-)*m;
if(ans&)
{
for(ll i=n;k>&&i>=;i--,k-=m)
if(i==x&&k>=y)
ans++;
}
else
{
for(ll i=;i<=n&&k>;i++,k-=m)
if(i==x&&k>=y)
ans++;
}
}
return ans;
}
int main()
{
cin>>n>>m>>k>>x>>y;
mx=mn=f(,,k);
for(ll i=;i<=n;i++)
for(ll j=;j<=m;j++)
mx=max(mx,f(i,j,k)),
mn=min(mn,f(i,j,k));
cout<<mx<<" "<<mn<<" "<<f(x,y,k);
}

自己的代码:

 #include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#define pi acos(-1.0)
#include<map>
#define inf 2e8+500
typedef long long ll;
using namespace std;
const int N=1e5+;
int main()
{
ll n,m,x,y;
ll k;
ll maxn,minn,ans=;
scanf("%lld%lld%lld%lld%lld",&n,&m,&k,&x,&y);
ll p1=m*(x-)+y,p2=(n-x)*m+y;
ll a=k/(m*n),b=k%(m*n);
if(k<m*n){
maxn=,minn=;
if(k>=p1){ans=;}
}
else {
if(n==){minn=a;
ans=b>=p1?a+:a;
maxn=b==?a:a+;
}
else {
if(k==m*n) maxn=minn=ans=;
else {
k-=m*n;
a=k/((n-)*m);
b=k%((n-)*m);
if(!b) {maxn=n==?a/+:a+;minn=+a/;}
else if(b!=) {maxn=n==?a/+:a+,minn=+a/;}
if(x<n&&x>){
ans=a+;
if(a&){if(b+m>=p1) ans++;}
else {if(b+m>=p2) ans++;}
}
else {
if(x==){
ans=a/+a%+;
if(a%==&&(b+m>=p2)) ans++;
}
else if(x==n) {
ans=a/+;
if(a&&&(b+m>=p1)) ans++;
}
}
}
}
}
printf("%lld %lld %lld\n",maxn,minn,ans);
return ;
}

总结:别人的代码更容易想到,写起来也方便一些,自己的思路不够清晰。。

最新文章

  1. 使用git把项目提交到github
  2. Leetcode 376. Wiggle Subsequence
  3. BZOJ4439——[Swerc2015]Landscaping
  4. &lt;十二&gt;面向对象分析之UML核心元素之节点和设备
  5. ASP.NET中身份验证的三种方法
  6. Web模板引擎本质前奏
  7. Java同步工具类总结
  8. stack 集合栈计算机 (摘)
  9. 如何使Label带有链接??此法感觉有点取巧!!!
  10. 鼠标放上去图片慢慢变大js 或 变大
  11. HTML5游戏开发进阶指南
  12. 201521123022 《Java程序设计》 第四周学习总结
  13. 获取AJAX加载的内容
  14. WebSphere--会话跟踪
  15. Asp.Net Core 2.1+的视图缓存(响应缓存)
  16. 我是如何通过学习拿到年薪80w
  17. qt 操作注册表,设置ie代理
  18. PyCharm基本用法
  19. elsearch
  20. Lambda 遍历

热门文章

  1. POS开发问题 - 缓存问题 - 02
  2. Android中关于XML的一个小问题——使用XML输出“&lt;”错误的问题
  3. tomcat的相关使用
  4. sqlalchemy的cascades
  5. 0 - python简介
  6. Altium_Designer-各种布线总结
  7. Selenium入门8 js调用
  8. mmap内存映射
  9. CUDA Texture纹理存储器 示例程序
  10. 通过eclipse启动tomcat设置JAVA_OPTS失败的解决方案