UVA - 815 Flooded

只需要对所有的单位square升序排序,从第一个开始往上添水即可;

#include <map>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define INF 10000000
using namespace std;
typedef long long LL;

const int maxn = 910;
double a[maxn];
int main()
{
    int kase=1,n,m;
    while(scanf("%d %d",&n,&m)==2){
        if(!n&&!m) break;

        int kk=0;
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++)
                scanf("%lf",&a[kk++]);
        sort(a,a+kk);

        double L;
        scanf("%lf",&L); L/=100;

        bool flag=false;
        double zen=0,posi,percentage;
        for(int i=1;i<kk;i++){
            double add=(a[i]-a[i-1])*i;
            if(zen+add>L){
                posi=((L-zen)/i)+a[i-1];
                percentage=(i*1.0)/kk;
                flag=true;
                break;
            }
            else zen+=add;
        }
        if(!flag){
            posi=((L-zen)/kk)+a[kk-1];
            percentage=1;
        }
        printf("Region %d\n",kase++);
        printf("Water level is %.2lf meters.\n",posi);
        printf("%.2lf percent of the region is under water.\n\n",percentage*100);
    }
    return 0;
}


### MAC Learning Priority: Concept and Implementation In the context of networking, **MAC learning priority** refers to the process by which a network switch or bridge determines the forwarding decisions for incoming frames based on the Media Access Control (MAC) addresses. This involves associating MAC addresses with specific ports and prioritizing traffic based on predefined rules or algorithms[^1]. #### 1. MAC Address Table and Learning Process A network switch maintains a MAC address table that maps MAC addresses to physical ports. When a frame arrives at a port, the switch learns the source MAC address and associates it with the incoming port. If the destination MAC address is already in the table, the frame is forwarded only to the corresponding port. Otherwise, the frame is flooded to all ports except the ingress port. The concept of priority can be introduced into this process by assigning weights or rankings to certain MAC addresses or traffic types. For example, critical applications such as voice over IP (VoIP) or video streaming may require higher priority in the MAC learning and forwarding process[^2]. ```python # Example of a simple MAC learning implementation in Python class Switch: def __init__(self): self.mac_table = {} def learn_mac(self, mac_address, port): """Learn the MAC address and associate it with the port.""" self.mac_table[mac_address] = port def forward_frame(self, frame): """Forward the frame based on the destination MAC address.""" dest_mac = frame['destination_mac'] if dest_mac in self.mac_table: port = self.mac_table[dest_mac] print(f"Forwarding frame to port {port}") else: print("Flooding frame to all ports") # Usage example switch = Switch() switch.learn_mac("00:11:22:33:44:55", 1) switch.forward_frame({"destination_mac": "00:11:22:33:44:55"}) ``` #### 2. Priority Mechanisms in MAC Learning Priority mechanisms in MAC learning can be implemented using various techniques: - **Weighted Scheduling**: Assign weights to different traffic classes and prioritize frames based on these weights. For instance, the Top(k) algorithm can be used to select the top k highest-priority frames for transmission. - **Queue Management**: Use multiple queues per port, where each queue corresponds to a specific priority level. Frames with higher priority are dequeued first. - **QoS Policies**: Integrate Quality of Service (QoS) policies to ensure that high-priority traffic receives preferential treatment during MAC learning and forwarding. #### 3. Practical Considerations When implementing MAC learning with priority, several factors must be considered: - **Scalability**: As the number of MAC addresses increases, the efficiency of the learning process and the size of the MAC table become critical concerns. - **Timeouts**: To prevent stale entries in the MAC table, switches typically implement aging mechanisms where unused entries are removed after a certain period. - **Security**: Unauthorized devices should not be allowed to flood the MAC table, which could lead to denial-of-service attacks.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值