Atcoder C - Half and Half

比萨订购问题
本文介绍了一个关于订购不同种类比萨的算法问题。通过使用贪心算法来确定如何以最低成本获得所需的A比萨和B比萨数量。文章提供了一段C++代码实现,并解释了算法的逻辑。

C - Half and Half


Time limit : 2sec / Memory limit : 256MB

Score : 300 points

Problem Statement

"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively.

Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.

Constraints

  • 1A,B,C5000
  • 1X,Y105
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C X Y

Output

Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas.


#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define LL long long
using namespace std;
int pra, prb, prc;
int x, y;
LL ans = 0;
int main()
{
	while (cin >> pra >> prb >> prc >> x >> y) {
		ans = 0;
		if (prc * 2 < pra + prb) {
			ans += min(x, y)*prc * 2;
			if (x > y)
				ans += (x - y)*pra;
			else ans += (y - x)*prb;
		} else {
			ans = x*pra + y*prb;
		}
		if (prc * 2 * max(x, y) < ans)
			ans = prc * 2 * max(x, y);
		cout << ans << endl;
	}
	return 0;
}
贪心算法,如果存在C的价格乘2低于A+B,对于A和B都要买的情况,全部选择C来进行购买。之后再分类讨论就OK了。



Guttman Split-Half 方法是一种用于评估测验内部一致性的统计方法,常用于心理测量和教育测量中。该方法通过将测验项目分成两半,计算两半之间的相关性,并利用斯皮尔曼-布朗公式(Spearman-Brown formula)对折半后的信度进行校正,从而估计整个测验的信度。 在 R 语言中实现 Guttman Split-Half 方法可以通过以下方式完成: 1. 使用 `psych` 包中的 `splitHalf` 函数可以直接计算 Split-Half 信度及其校正值。 示例代码如下: ```r # 安装并加载 psych 包 install.packages("psych") library(psych) # 假设 dat 是一个数据框,其中每一列代表一个题目得分 result <- splitHalf(dat, raw = TRUE, brute = FALSE) print(result) ``` 该函数会返回多个 Split-Half 分法下的相关系数以及经过斯皮尔曼-布朗公式校正后的最大和最小信度估计值。 2. 手动实现 Split-Half 方法也可以使用基础 R 函数进行操作。例如将题目平均分为前后两半,计算每半的总分,再计算皮尔逊相关系数并应用斯皮尔曼-布朗公式: ```r # 假设 data 是一个向量或矩阵,包含测验的题目得分 n_items <- ncol(data) half <- n_items %/% 2 # 将题目分为前半部分和后半部分 first_half <- data[, 1:half] second_half <- data[, (half + 1):n_items] # 计算每半的总分 sum_first <- rowSums(first_half) sum_second <- rowSums(second_half) # 计算皮尔逊相关系数 r <- cor(sum_first, sum_second) # 应用 Spearman-Brown 校正公式 corrected_r <- (2 * r) / (1 + r) ``` 3. 可以进一步扩展 Split-Half 方法,尝试不同分法(如奇偶题号分组),并通过循环遍历所有可能的组合来提高估计的稳定性。 4. 若需可视化 Split-Half 结果,可使用 `ggplot2` 包绘制前后两半得分的相关散点图,并添加趋势线。 ```r library(ggplot2) df <- data.frame(first = sum_first, second = sum_second) ggplot(df, aes(x = first, y = second)) + geom_point() + geom_smooth(method = "lm", se = FALSE) + labs(title = "Split-Half Correlation", x = "First Half Score", y = "Second Half Score") ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值