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. hibernate课程 初探一对多映射2-4 Mysql创建数据库表

    1 本节内容: mysql 数据库建表(班级表和学生表) Create table grade(gid varchar(32) primary key, gname varchar(32) not n ...

  2. jQuery的定时执行和延迟执行

    jQuery的定时执行和延迟执行 //延迟执行 setTimeout(function(){ console.log("实战授课,100%就业"); },600); //定时执行 ...

  3. JS在与lua的交互心得

    最近在写一个项目,前端技术使用的是Vue,在与lua的交互过程,是通过一个公共JS,前端调用公共js的方法给lua发送命令,lua接到命令,去执行一些方法,然后又通过回调返回到了前端,由于是第一次写这 ...

  4. Cloud Computing

    More numbers, More power. We waste much more every day. Everything can be connectible through specia ...

  5. ArcGIS API for JavaScript开发初探——基本地图组件使用

    1.前言 在上一篇我们已经我们已经讲述了第一个地图应用程序的HelloMap的创建过程,这一篇我们来讲述基本地图组件:Home Button.比例尺.鹰眼图的使用方法. 2.基本地图组件 在ArcGI ...

  6. nginx配置https服务器

    方法一 1.创建证书 #cd /usr/local/nginx/conf #openssl genrsa -des3 -out server.key 1024 #openssl req -new -k ...

  7. 关于SAP UI5数据绑定我的一些原创内容

    如何查找SAP UI5官方关于数据绑定的文档: https://sapui5.hana.ondemand.com/ 点Documentation: Filter里输入data就能看到Data Bind ...

  8. SAP CRM WebClient UI和Fiori UI混搭并存

    SAP CRM里有个功能可以创建HANA live report,消费HANA Studio里创建的模型. 最后创建好的report长这个样子: 具体创建步骤可以参考我的博客Step by Step ...

  9. 问答 请问使用OK("raw:jpg")能返回多张图片吗

     请问使用OK("raw:jpg")能返回多张图片吗  发布于 28天前  作者 qq_3aeeb0ad  78 次浏览  复制  上一个帖子  下一个帖子  标签: 无 @At( ...

  10. hdu-2844&&POJ-1742 Coins---多重背包

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2844 题目大意: Tony想要买一个东西,他只有n中硬币每种硬币的面值为a[i]每种硬币的数量为c[ ...