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

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

Codeforces Round #392 (Div. 2) Unfair Poll的更多相关文章

  1. 【找规律】Codeforces Round #392 (Div. 2) C. Unfair Poll

    C. Unfair Poll time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. Codeforces Round #392 (Div. 2) A B C 水 模拟 暴力

    A. Holiday Of Equality time limit per test 1 second memory limit per test 256 megabytes input standa ...

  3. Codeforces Round #392 (Div. 2) F. Geometrical Progression

    原题地址:http://codeforces.com/contest/758/problem/F F. Geometrical Progression time limit per test 4 se ...

  4. Virtual Codeforces Round #392 (Div. 2)

    下午闲来无事开了一场Virtual participation 2h就过了3道水题...又跪了..这只是Div. 2啊!!! 感觉这次直接就是跪在了读题上,T1,T2读题太慢,T3还把题读错了 要是让 ...

  5. Codeforces Round #392 (Div. 2) - C

    题目链接:http://codeforces.com/contest/758/problem/C 题意:给定N*M矩阵的教室,每个位置都有一个学生,Sergei坐在[X,Y],然后老师会问K个问题,对 ...

  6. Codeforces Round #392 (Div. 2) - B

    题目链接:http://codeforces.com/contest/758/problem/B 题意:给定n个点灯的情况,灯只有四种颜色RBGY,然后如果某个灯坏了则用'!'表示,现在要求将坏的灯( ...

  7. Codeforces Round #392 (Div. 2) - A

    题目链接:http://codeforces.com/contest/758/problem/A 题意:给定N个城市的福利,国王现在想让每个城市的福利都一致.问最少需要花多少钱使得N个城市的福利值都一 ...

  8. Codeforces Round #392 (Div. 2)-758D. Ability To Convert(贪心,细节题)

    D. Ability To Convert time limit per test 1 second Cmemory limit per test 256 megabytes input standa ...

  9. Codeforces Round #392 (Div. 2)

    D题,给出n,k,k是n进制数,但是大于十进制时,它的表示方法仍为十进制那种,比如16进制下的15,我们可以看成就是15,或者1|5,也就是1×16+5 = 21,让你求出能表达的最小十进制数 从后面 ...

随机推荐

  1. 收藏 创建第一个mvc

    http://blog.csdn.net/sdtsfhh/article/details/8201956

  2. agc001E - BBQ Hard(dp 组合数)

    题意 题目链接 Sol 非常妙的一道题目. 首先,我们可以把\(C_{a_i + b_i + a_j + b_j}^{a_i + a_j}\)看做从\((-a_i, -b_i)\)走到\((a_j, ...

  3. Mysql慢查询 [第一篇]

    一.简介 开启慢查询日志,可以让MySQL记录下查询超过指定时间的语句,通过定位分析性能的瓶颈,才能更好的优化数据库系统的性能. 二.参数说明 slow_query_log 慢查询开启状态slow_q ...

  4. 认识less和webstrom的less配置

    认识less和webstrom的less配置 今天完成的事情: 首先第一件事情是,整理一下常用的颜色摄取 #F1F1F1 google的设置页面的body的背景颜色 #FFF 为google的内容块的 ...

  5. 手把手教你用android studio创建第一个安卓程序加载html5页面(二)

    经过上一篇,我们已经可以打开html页面了,但是有很多细节方面的内容我们还需要调整. 打开链接的问题 细心的网友可能已经发现,打开百度页面后,点击顶部的链接,会在手机的浏览器中打开相应的页面,这显然不 ...

  6. android studio gradle统一管理版本

    创建config.gradle ext { android = [ compileSdkVersion : 26, buildToolsVersion : "26.0.2", mi ...

  7. tfs2012安装

    今天正在配置tfs的服务器.要先安装net 3.5 ps1.要选择安装reportingservers 来启动报表功能.

  8. C#多线程Thread

    在项目中经常用到线程Thread,先做个简单记录,后面再完善下,方便以后参考.本人技术有限,如有不同见解之处,欢迎博友批评指正. 执行的线程Thread分无参数的,一个参数,多个参数的.直接看代码吧. ...

  9. php的yii框架开发总结10

    1.CActiveForm是Chtml类的封装,但是它有数据验证的功能,有三种方式:服务器端.客户端.Ajax数据验证. 服务器端验证:当整个表单页面被提交后,在服务器端 进行验证.如果存在任何验证错 ...

  10. 如何在SecureCRT中给linux上传和下载文件

    方法/步骤     需要上传或者下载,需要使用rz和sz命令.如果linux上没有这两个命令工具,则需要先安装.可以使用yum安装.运行命令yum install lrzsz.   安装完成后就可以使 ...