pat 1070

1070. Mooncake (25)

时间限制
100 ms
内存限制
32000 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types of fillings and crusts can be found in traditional mooncakes according to the region's culture. Now given the inventory amounts and the prices of all kinds of the mooncakes, together with the maximum total demand of the market, you are supposed to tell the maximum profit that can be made.

Note: partial inventory storage can be taken. The sample shows the following situation: given three kinds of mooncakes with inventory amounts being 180, 150, and 100 thousand tons, and the prices being 7.5, 7.2, and 4.5 billion yuans. If the market demand can be at most 200 thousand tons, the best we can do is to sell 150 thousand tons of the second kind of mooncake, and 50 thousand tons of the third kind. Hence the total profit is 7.2 + 4.5/2 = 9.45 (billion yuans).

Input Specification:

Each input file contains one test case. For each case, the first line contains 2 positive integers N (<=1000), the number of different kinds of mooncakes, and D (<=500 thousand tons), the maximum total demand of the market. Then the second line gives the positive inventory amounts (in thousand tons), and the third line gives the positive prices (in billion yuans) of N kinds of mooncakes. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print the maximum profit (in billion yuans) in one line, accurate up to 2 decimal places.

Sample Input:
3 200
180 150 100
7.5 7.2 4.5
Sample Output:
9.45

#include <stdio.h>
#include <algorithm>
using namespace std;

struct Price
{
	double pce;
	int id;
} price[1010];

int n;
double d;
double tons[1010];

bool cmp(Price a, Price b)
{
	return a.pce > b.pce;
}
int main()
{
	int i, j;

	while(scanf("%d%lf", &n, &d) != EOF)
	{
		for(i = 1; i <= n; i++)
		{
			scanf("%lf", &tons[i]);
		}

		for(i = 1; i <= n; i++)
		{
			scanf("%lf", &price[i].pce);
			price[i].id = i;
		}

		for(i = 1; i <= n; i++)
			price[i].pce = price[i].pce / tons[i];

		double sum = 0;
		int index = 1;

		sort(price + 1, price + n + 1, cmp);

		while(d > 0 && index <= n)
		{
			double max = 0;
			int cnt = price[index].id;

			if(tons[cnt] < d)
			{
				sum = sum + price[index].pce * tons[cnt];
				d = d - tons[cnt];
			}
			else
			{
				sum = sum + price[index].pce * d;
				d = 0;
			}

			index++;
		}

		printf("%.2lf\n", sum);
	}
	return 0;
}


在信息技术领域,"PAT" 是一个常见的缩写,通常指 **端口地址转换(Port Address Translation)**。这是一种网络地址转换(NAT)的形式,允许内部网络中的多个设备共享一个公共IP地址进行互联网通信。PAT 通过分配不同的端口号来区分来自不同内部设备的流量,从而实现地址的复用。这种方式不仅节省了IPv4地址资源,还增强了内部网络的安全性,因为外部网络无法直接访问内部网络中的具体设备[^1]。 ### 工作原理 在 PAT 过程中,当内部网络中的设备发起对外连接时,路由器或防火墙会记录下该设备的私有 IP 地址和端口号,并将其转换为公共 IP 地址和一个新的唯一端口号。当外部响应返回时,设备会根据端口号将数据包转发回正确的内部设备。这种机制在家庭宽带和企业网络中广泛使用,以确保多个用户可以共享一个公网 IP 地址上网。 ### 示例配置 以下是一个简单的 Cisco 路由器上配置 PAT 的示例命令: ```bash Router(config)# interface fa0/0 Router(config-if)# ip address 192.168.1.1 255.255.255.0 Router(config-if)# exit Router(config)# interface fa0/1 Router(config-if)# ip address 203.0.113.45 255.255.255.0 Router(config-if)# exit Router(config)# ip nat inside source list 1 interface fa0/1 overload Router(config)# access-list 1 permit 192.168.1.0 0.0.0.255 Router(config)# interface fa0/0 Router(config-if)# ip nat inside Router(config-if)# exit Router(config)# interface fa0/1 Router(config-if)# ip nat outside ``` ### 其他含义 除了端口地址转换外,"PAT" 在不同上下文中也可能有其他含义。例如,在软件开发中,PAT 可能指 **Personal Access Token**,这是一种用于身份验证的令牌,常用于访问 GitHub 等代码托管平台的 API。此外,在无线通信领域,PAT 可能代表 **Packet Arrival Time**,用于描述数据包到达的时间戳信息。 ### 应用场景 PAT 技术广泛应用于各种网络环境中,特别是在 IPv4 地址资源紧张的情况下。它不仅解决了地址不足的问题,还为内部网络提供了一定程度的安全保护。在云计算和虚拟化环境中,PAT 也常用于为虚拟机分配网络地址,确保它们可以正常访问外部网络。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值