Codeforces Round #392 (Div. 2) C - Unfair Poll codeforces

本文解析了一道关于教室中教师提问模式的算法题。该题要求计算在特定的提问顺序下,每个学生的最大和最小被提问次数以及指定学生被提问的次数。文章通过分析提问模式的周期性特点,提供了解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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; 

The order of asking pupils in the second test: 

  1. the pupil from the first row who seats at the first table; 
  2. the pupil from the first row who seats at the second table; 
  3. the pupil from the second row who seats at the first table; 
  4. the pupil from the second row who seats at the second table; 
  5. the pupil from the third row who seats at the first table; 
  6. the pupil from the third row who seats at the second table; 
  7. the pupil from the fourth row who seats at the first table; 
  8. the pupil from the fourth row who seats at the second table, it means it is Sergei; 
  9. the pupil from the third row who seats at the first table;


题目大意:有一个n*m大小的教室,每个座位都坐上了人,老师按照从第一排到最后一排,在从倒数第二排到第一排,再从第一排到最后一排,每排从第一个人到第m个人,这么提问k次,问提问最多的人的提问次数是多少,最少的提问次数,和x,y坐标的那个座位的提问次数。




像图片那样,第一行到最后一行,在到第二行为一个循环,每个循环第一行和最后一行到递增为1,中间那些递增2,所以我们得出2*(n-1)*m个格子为一个周期,k/t*2 为中间的增长整周期。k/t 为头尾增长整周期, k%t 为整周期之后剩余的提问次数。
#include "stdio.h"
#include "string.h"
#include "algorithm"
using namespace std;
typedef long long ll;
int n,m,X,Y;
ll K,ans[110][110];
int main()
{
    int i,j,t;
    long long mn = 1e18, mx = 0;
    scanf("%d%d%lld%d%d",&n,&m,&K,&X,&Y);
    t = (n > 1 ? (2*n-2)*m : m);
    for(i=2;i<n;i++)
        for(j=1;j<=m;j++)
            ans[i][j] = K/t*2;
    for(j=1;j<=m;j++)
        ans[1][j] = ans[n][j] = K/t;
    K %= t;
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
            if(K > 0)
                ans[i][j]++, K--;
    for(i=n-1;i>1;i--)
        for(j=1;j<=m;j++)
            if(K > 0)
                ans[i][j]++, K--;
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++){
            mn = (mn < ans[i][j] ? mn : ans[i][j]);
            mx = (mx > ans[i][j] ? mx : ans[i][j]);
        }
    printf("%lld %lld %lld\n",mx,mn,ans[X][Y]);
    return 0;
}

内容概要:本文探讨了在MATLAB/SimuLink环境中进行三相STATCOM(静态同步补偿器)无功补偿的技术方法及其仿真过程。首先介绍了STATCOM作为无功功率补偿装置的工作原理,即通过调节交流电压的幅值和相位来实现对无功功率的有效管理。接着详细描述了在MATLAB/SimuLink平台下构建三相STATCOM仿真模型的具体步骤,包括创建新模型、添加电源和负载、搭建主电路、加入控制模块以及完成整个电路的连接。然后阐述了如何通过对STATCOM输出电压和电流的精确调控达到无功补偿的目的,并展示了具体的仿真结果分析方法,如读取仿真数据、提取关键参数、绘制无功功率变化曲线等。最后指出,这种技术可以显著提升电力系统的稳定性与电能质量,展望了STATCOM在未来的发展潜力。 适合人群:电气工程专业学生、从事电力系统相关工作的技术人员、希望深入了解无功补偿技术的研究人员。 使用场景及目标:适用于想要掌握MATLAB/SimuLink软件操作技能的人群,特别是那些专注于电力电子领域的从业者;旨在帮助他们学会建立复杂的电力系统仿真模型,以便更好地理解STATCOM的工作机制,进而优化实际项目中的无功补偿方案。 其他说明:文中提供的实例代码可以帮助读者直观地了解如何从零开始构建一个完整的三相STATCOM仿真环境,并通过图形化的方式展示无功补偿的效果,便于进一步的学习与研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值