Unfair Poll (模拟)

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列学生,有一位老师在课上会问k个问题,在行上,是按照1,2。。。。n-1,n,n-1.。。。1这样的顺序提问,求学生当中回答问题个数最多和最少的个数,以及在第x行第y位的同学回答的问题数。

解题思路:不难发现,当n>1时,1,2,……,n-1,n,n-1,……3,2为一个循环节,即有2*n-2行,其中每个循环节第1行以及第n行都只回答一次,其他都回答了两次,然后直接用二维数组进行模拟即可。注意细节的地方。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll ans[105][105];
int main()
{
    ll n,m,k,x,y;
    ll t,i,j;
    ll rest,maxans,minans;
    while(cin>>n>>m>>k>>x>>y)
    {
        maxans=-1;
        minans=1000000000000000005;


        if(n>1)
            t=(n*2-2)*m;
        else
            t=m;

        for(i=2;i<=n-1;i++)
        {
            for(j=1;j<=m;j++)
            {
                ans[i][j]=k/t*2;
            }
        }

        for(i=1;i<=m;i++)
        {
            ans[1][i]=ans[n][i]=k/t;
        }
        rest=k%t;

        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                if(rest)
                {
                    ans[i][j]++;
                    rest--;
                }
            }
        }

        for(i=n-1;i>1;i--)
        {
            for(j=1;j<=m;j++)
            {
                if(rest)
                {
                    ans[i][j]++;
                    rest--;
                }
            }
        }

        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                maxans=max(maxans,ans[i][j]);
                minans=min(minans,ans[i][j]);
            }
        }
        printf("%lld %lld %lld\n",maxans,minans,ans[x][y]);
    }

    return 0;
}

在数据中心设置中,队列填充、使用等价多路径路由(ECMP)提高负载对短流不公平等情况与TCP连接中断存在密切联系。 ### 队列填充导致TCP中断 当数据中心网络中的队列被填满时,会出现数据包丢失的情况。TCP协议依赖于数据包的有序传输和确认机制来保证数据的可靠传输。队列填充可能导致以下问题: - **数据包丢失**:队列满时,新进入的数据包会被丢弃。TCP发送方在一定时间内没有收到数据包的确认(ACK),会认为数据包丢失,从而触发重传机制。如果频繁出现数据包丢失,会导致大量的重传,增加网络拥塞,最终可能导致TCP连接中断。 - **延迟增加**:队列填充会使数据包在队列中等待的时间变长,导致网络延迟增加。TCP协议对延迟非常敏感,过长的延迟会影响TCP的拥塞控制机制,使发送方降低发送速率,甚至可能导致连接超时中断。 ### ECMP对短流不公平导致TCP中断 ECMP是一种在数据中心网络中常用的负载均衡技术,它允许数据包通过多条等价路径进行传输。然而,ECMP对短流可能存在不公平性,这也会影响TCP连接的稳定性: - **短流竞争劣势**:在ECMP环境下,长流可能会占用大部分可用路径,导致短流只能选择较少的路径。短流在竞争路径资源时处于劣势,可能会面临更高的延迟和数据包丢失率,从而影响TCP连接的正常运行。 - **路径选择问题**:ECMP的路径选择通常是基于哈希算法,可能会导致某些短流始终被分配到拥塞的路径上,而其他路径却空闲。这种不均衡的路径分配会使短流的TCP连接更容易中断。 ### 综合影响 队列填充和ECMP对短流的不公平性可能相互作用,进一步加剧TCP连接中断的风险。例如,队列填充导致的数据包丢失和延迟增加会使短流的TCP连接更加脆弱,而ECMP对短流的不公平性又会使短流更容易受到队列填充的影响。 ```python # 模拟TCP重传机制 import time # 模拟数据包发送 def send_packet(packet): print(f"Sending packet: {packet}") # 模拟网络延迟 time.sleep(0.1) # 模拟数据包丢失 import random if random.random() < 0.2: return False return True # 模拟TCP发送方 def tcp_sender(packets): for packet in packets: while True: if send_packet(packet): print(f"Packet {packet} sent successfully") break else: print(f"Packet {packet} lost, retransmitting...") # 测试 packets = [1, 2, 3, 4, 5] tcp_sender(packets) ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值