Codeforces Round #392 (Div. 2) Unfair Poll
1 second
256 megabytes
standard input
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:
- 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;
思路:一个稍微麻烦一点的模拟..
思路清晰的代码:
#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的更多相关文章
- 【找规律】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 ...
- 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 ...
- Codeforces Round #392 (Div. 2) F. Geometrical Progression
原题地址:http://codeforces.com/contest/758/problem/F F. Geometrical Progression time limit per test 4 se ...
- Virtual Codeforces Round #392 (Div. 2)
下午闲来无事开了一场Virtual participation 2h就过了3道水题...又跪了..这只是Div. 2啊!!! 感觉这次直接就是跪在了读题上,T1,T2读题太慢,T3还把题读错了 要是让 ...
- Codeforces Round #392 (Div. 2) - C
题目链接:http://codeforces.com/contest/758/problem/C 题意:给定N*M矩阵的教室,每个位置都有一个学生,Sergei坐在[X,Y],然后老师会问K个问题,对 ...
- Codeforces Round #392 (Div. 2) - B
题目链接:http://codeforces.com/contest/758/problem/B 题意:给定n个点灯的情况,灯只有四种颜色RBGY,然后如果某个灯坏了则用'!'表示,现在要求将坏的灯( ...
- Codeforces Round #392 (Div. 2) - A
题目链接:http://codeforces.com/contest/758/problem/A 题意:给定N个城市的福利,国王现在想让每个城市的福利都一致.问最少需要花多少钱使得N个城市的福利值都一 ...
- 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 ...
- Codeforces Round #392 (Div. 2)
D题,给出n,k,k是n进制数,但是大于十进制时,它的表示方法仍为十进制那种,比如16进制下的15,我们可以看成就是15,或者1|5,也就是1×16+5 = 21,让你求出能表达的最小十进制数 从后面 ...
随机推荐
- Hibernate课程 初探一对多映射4-2 cascade级联属性
1 级联属性:hibernate一方和多方设置关联关系,当一方发生相应修改时(见下表),多方不用进行显式修改,也能进行相应修改. 级联在一方和多方xml中都可以设置 属性值 含义和作用 all 对 ...
- ORACLE:毫秒与日期的相互转换,获取某天的信息
毫秒转换为日期 SELECT TO_CHAR(1406538765000 / (1000 * 60 * 60 * 24) + TO_DATE('1970-01-01 08:00:00', 'YYYY- ...
- 使用C#实现计划任务(corn job)
维基百科上是这样描述计划任务的: “Cron is a time-based job scheduler in Unix-like computer operating systems. Cron i ...
- 再谈 Struts1.x 的运行机制
1.Action类 execute 方法 ActionMapping 对应 <action path="user" type="myuser.UserAction& ...
- 从PeopleEditor控件中取出多用户并更新到列表
如果一个列表中有一个字段类型为用户或用户组,并且设置为用户,允许多值的话,那么用代码进行更新的时候就必须将这个字段的值赋成SPFieldUserValueCollection类型,以下代码即为从Peo ...
- python从字符串中提取数字,使用正则表达式
使用正则表达式 import re D = re.findall(r"\d+\.?\d*",line) print(D) -7.23246 10.8959 5.19534 0.06 ...
- 两台windows内网之间快速复制大量(上百万个)小文件(可用于两台服务器之间)
用各种FTP工具(各种主动被动)都不好使.经测试,用以下的(协议.工具等),在双千兆网卡下,传输大量1M的文件可以达到每秒60多M: windows文件共享(SMB协议)(若是08 r2 数据中心版, ...
- 使用dao时,如何同时使用动态表名和过滤字段?
使用dao时,如何同时使用动态表名和过滤字段? 发布于 630天前 作者 wukonggg 316 次浏览 复制 上一个帖子 下一个帖子 标签: 无 如题.求样例代码 1 回复 wend ...
- HDU(1016),打素数环
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1016 哈哈,状态来了就是不一样,很快就A了. 注意的位置是,最后一个点,要与第一个点比较. #incl ...
- node执行环境
nodejs本质上是一个javascript的执行环境,只是由于他的封装,加上更多web底层的一个处理,赋予了更多的能力,那么执行环境到底是什么呢,我们到浏览器里面体验看看,在chrome里面控制台, ...