平常水题 — Codeforces Round #415 (Div. 2) B. Summer sell-off (贪心 + 错误总结)

本文介绍了一个关于夏销策略的问题,通过分析商店计划中每一天的产品库存和客户流量来最大化总销售额。通过对不同天数进行选择性加倍销售,可以有效提高产品销量。
B. Summer sell-off
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant.

Shop, where Noora is working, has a plan on the following n days. For each day sales manager knows exactly, that in i-th day ki products will be put up for sale and exactly li clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump.

For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any f days from n next for sell-outs. On each of f chosen days the number of products were put up for sale would be doubled. Thus, if on i-th day shop planned to put up for sale ki products and Noora has chosen this day for sell-out, shelves of the shop would keep 2·ki products. Consequently, there is an opportunity to sell two times more products on days of sell-out.

Noora's task is to choose f days to maximize total number of sold products. She asks you to help her with such a difficult problem.

Input
The first line contains two integers n and f (1 ≤ n ≤ 105, 0 ≤ f ≤ n) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out.

Each line of the following n subsequent lines contains two integers ki, li (0 ≤ ki, li ≤ 109) denoting the number of products on the shelves of the shop on the i-th day and the number of clients that will come to the shop on i-th day.

Output
Print a single integer denoting the maximal number of products that shop can sell.

Examples
input
4 2
2 1
3 5
2 3
1 5
output
10
input
4 1
0 2
0 3
3 5
0 6
output
5
Note
In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units.

In the second example it is possible to sell 5 products, if you choose third day for sell-out.


题意:先输入n,f,分别代表有 n 天,可以让任意 f 天的的物品数量翻倍。接下来有n行,第 i 行有两个数 ki,li,分别代表在第 i 天有  ki  件物品,有 li 个顾客。每个顾客都会买一件物品。问 n 天后最多卖出多少件物品。


错误思路:一开始写是先把每天的物品翻倍后,求出这一天最多能卖出多少件后记录并从大到小排序。选取前f大的天数并标记前f大的天数。最后加上没被标记的天不翻倍最多能卖出多少件。这个思路是错误的,因为要求的是在原先不翻倍的基础上,任意f天翻倍后最多能增加卖出的件数。如这组数据

2     1

2     4

100 101

按照我的错误算法得到的答案是103,而实际正确的答案是104。


正确思路:1  当天的存货量大于等于需求量的时候,这一天的存货量是不需要翻倍的
     2  当天存货量小于需求量的时候,先让这一天的存货量翻倍,求出当天 ”可增加“ 的销售量
         然后根据可增加的销售量从大到小排序,选出前f天。


#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<stack>
#include<vector>
using namespace std;

const int maxn = 1e5 + 5;

long long k[maxn],l[maxn],s[maxn];

long long cmp(long long a,long long b){
	return a > b;
}

int main(){
	int n,f;
	long long ans = 0,sum;
	scanf("%d %d",&n,&f);
	for(int i = 1;i <= n;i++){
		scanf("%I64d %I64d",&k[i],&l[i]);
		if(l[i] > k[i]){
			if(2 * k[i]  <= l[i]) s[i] = k[i];
			else s[i] = l[i] - k[i];
		}
		else{
			s[i] = 0;
			k[i] = l[i];
		}
	}
	sort(s + 1,s + n + 1,cmp);
	for(int i = 1;i <= f;i++) ans += s[i];
	for(int i = 1;i <= n;i++) ans += k[i];
	printf("%I64d",ans);
}

内容概要:本文围绕可变桨叶四旋翼无人机的规范控制与点对点运动模拟展开,重点研究优化推力分配策略在翻转动作中的应用与性能比较。通过Matlab代码实现,构建了四旋翼动力学模型,并设计了多种控制算法以实现精确的姿态调整与轨迹跟踪。研究对比了不同推力分配方案在执行高机动性翻转动作时的稳定性、能耗效率与响应速度,旨在提升无人机在复杂飞行任务中的动态性能与控制精度。该仿真研究为无人机飞控系统的设计与优化提供了理论依据和技术支持。; 适合人群:具备一定自动控制理论基础和Matlab编程能力,从事无人机控制、飞行器动力学或机器人系统研究的科研人员及研究生。; 使用场景及目标:① 实现四旋翼无人机在三维空间中的精确点对点运动控制;② 对比分析不同推力分配策略在执行翻转等高难度动作时的控制效果与能耗表现,优化飞行性能;③ 为无人机自主飞行、特技飞行及复杂环境下的机动控制提供算法验证平台。; 阅读建议:此资源以Matlab仿真为核心,建议读者结合相关控制理论知识,深入理解代码实现细节,重点关注动力学建模、控制律设计与推力分配模块。在学习过程中,应动手调试参数,复现文中翻转动作的仿真结果,并尝试拓展至其他复杂飞行任务,以加深对无人机控制机理的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值