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,让你求出能表达的最小十进制数 从后面 ...
随机推荐
- The ninth day
a good egg 可不是好的鸡蛋的意思哦 它等同于 a good person 大好人的意思 eg: We all think he is a good egg. 我们都认为他是一个好人. I t ...
- HTML超链接实用
1.文本链接: <a href="http://www.meng.com/" target="_blank">访问meng!</a> 2 ...
- 安装office提示Office 16 Click-to-Run Extensibility Component
今天安装office时,提示Office 16 Click-to-Run Extensibility Component或者Office 15 Click-to-Run Extensibility C ...
- centos7 gearmand-1.1.15打包rpm
wget https://github.com/gearman/gearmand/releases/download/1.1.15/gearmand-1.1.15.tar.gz -O /root/rp ...
- Jetty服务器的使用
Jetty 是一个开源的servlet容器,它为基于Java的web容器,例如JSP和servlet提供运行环境.Jetty是使用Java语言编写的,它的API以一组JAR包的形式发布.开发人员可以将 ...
- CentOS-6.5安装配置JDK-7
安装说明 系统环境:centos-6.5安装方式:rpm安装 软件:jdk-7-linux-x64.rpm下载地址:http://www.oracle.com/technetwork/java/jav ...
- Vue.js-创建Vue项目(Vue项目初始化)并不是用Webstrom创建,只是用Webstrom打开
我犯的错误:作为vue小白,并不知道还要单独去创建初始的vue项目,于是自己在webstrom中建了一个Empty Project, 在其中新增了一个js文件,就开始import Vue from “ ...
- Torch.no_grad()影响MSE损失
相关描述 https://discuss.pytorch.org/t/torch-no-grad-affecting-outputs-loss/28595/3 今天在训练网络的时候,发现mseloss ...
- Convolutional Neural Networks from deep learning (assignment 1 from week 1)
Convolutional Neural Networks https://www.coursera.org/learn/convolutional-neural-networks/home/welc ...
- Family Gathering at Christmas(思维题)
Family Gathering at Christmas 时间限制: 1 Sec 内存限制: 128 MB提交: 13 解决: 4[提交] [状态] [讨论版] [命题人:admin] 题目描述 ...