Educational Codeforces Round 165 (Rated for Div. 2) (C、D)

devtools/2024/9/24 13:38:02/

1969C - Minimizing the Sum 

        题意:

        思路:观察到操作数很小,最值问题+操作数很容易想到dp,用dp[i][j]表示第i个元素,操作了j次的最小值总和,转移的时候枚举连续操作了几次即可,而连续操作了几次即将a_{i-k} ...a_{i}全部变成其中的最小值。

        

// Problem: C. Minimizing the Sum
// Contest: Codeforces - Educational Codeforces Round 165 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1969/problem/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second 
#define int long long
#define endl '\n'
const LL maxn = 4e05+7;
const LL N = 5e05+10;
const LL mod = 1e09+7;
const int inf = 0x3f3f3f3f;
const LL llinf = 5e18;
typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆
priority_queue<LL> ma;//大根堆
LL gcd(LL a, LL b){return b > 0 ? gcd(b , a % b) : a;
}LL lcm(LL a , LL b){return a / gcd(a , b) * b;
}
int n , m;
vector<int>a(N , 0);
void init(int n){for(int i = 0 ; i <= n ; i ++){a[i] = 0;}
}
void solve() 
{cin >> n >> m;int dp[n + 5][m + 5];memset(dp , 0x3f , sizeof dp);dp[0][0] = 0;for(int i = 1 ; i <= n ; i ++){cin >> a[i];}for(int i = 1 ; i <= n ; i ++){for(int j = 0 ; j <= min(i - 1 , m); j ++){//使用了j次for(int k = 0 ; k <= j ; k ++){//连续使用k次int minn = a[i];for(int t = i ; t >= i - k ; t --)minn = min(a[t] , minn);dp[i][j] = min(dp[i][j] , dp[i - k - 1][j - k] + (k + 1) * minn); }}}
//	cout << dp[4][2] << endl;int ans = llinf;for(int i = 0 ; i <= m ; i++){ans = min(ans , dp[n][i]);}cout << ans << endl;
}            
signed main() 
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);int t=1;cin>>t;while(t--){solve();}return 0;
}

1969D - Shop Game 

        题意:

        思路:

        思考Alice可以选择哪些商品:即a_{i} <= b_{i}的商品都可以被选择。

        思考给定一个商品集合,Bob该如何选择:按照b的大小从大到小排列,前k个设为免费。

        再思考这样一定是最优的么?不一定

        若Alice抛弃一个商品,那么他将会少花费a_{i}金币,而后Bob会重新按照规则选取k个,因此有可能最终花费的金币数会减少。

        思考Alice按照怎么样的顺序抛弃商品:1、原先没有被Bob选中的商品一定不会被Alice抛弃。2、Alice抛弃的是被Bob选中的当中a最大的那一个。

        因此我们用两个优先队列来维护被Bob选中的那些商品以及没有被Bob选中的商品。

        随后我们按照顺序逐个抛弃商品,求整个过程中所赚取金币的最大值即可。

        

// Problem: D. Shop Game
// Contest: Codeforces - Educational Codeforces Round 165 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1969/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second 
#define endl '\n'
#define int long long
const LL maxn = 4e05+7;
const LL N = 5e05+10;
const LL mod = 1e09+7;
const int inf = 0x3f3f3f3f;
const LL llinf = 5e18;
typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆
priority_queue<LL> ma;//大根堆
LL gcd(LL a, LL b){return b > 0 ? gcd(b , a % b) : a;
}LL lcm(LL a , LL b){return a / gcd(a , b) * b;
}
int n , m;
vector<int>a(N , 0);
void init(int n){for(int i = 0 ; i <= n ; i ++){a[i] = 0;}
}
bool cmp(pl a , pl b){if(a.x != b.x){return a.x > b.x;}else{return a.y < b.y;}
}
void solve() 
{cin >> n >> m;vector< pair<int,int> >p(n + 5);for(int i = 0 ; i < n ; i ++)cin >> p[i].y;for(int i = 0 ; i < n ; i ++)cin >> p[i].x;vector< pair<int,int> > ans;LL cost = 0;for(int i = 0 ; i < n ; i ++){if(p[i].y <= p[i].x){ans.pb(p[i]);cost -= p[i].y;}}sort(ans.begin() , ans.end() , cmp);priority_queue<LL> ma;//拿走的for(int i = 0 ; i < min(m , (int)ans.size()) ; i ++){ma.push(ans[i].y);}priority_queue<pl> ma1;//需要购买的		for(int i = m ; i < ans.size() ; i ++){ma1.push({ans[i].x , ans[i].y});cost += ans[i].x;}int maxx = cost; while(!ma.empty() && !ma1.empty()){cost += ma.top();cost -= ma1.top().first;ma.pop();ma.push(ma1.top().second);ma1.pop();maxx = max(maxx , cost);}cout << max(maxx , 0LL) << endl;
}            
signed main() 
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);int t=1;cin>>t;while(t--){solve();}return 0;
}


http://www.ppmy.cn/devtools/32749.html

相关文章

【深度学习基础(3)】初识神经网络之深度学习hello world

文章目录 一. 训练Keras中的MNIST数据集二. 工作流程1. 构建神经网络2. 准备图像数据3. 训练模型4. 利用模型进行预测5. (新数据上)评估模型精度 本节将首先给出一个神经网络示例&#xff0c;引出如下概念。了解完本节后&#xff0c;可以对神经网络在代码上的实现有一个整体的了…

电磁波的极化形式

极化是电磁波的一个固有属性,是指电磁波的电场矢量末端的轨迹曲线,电磁波的极化 状态由这条曲线所决定,电场的振动方向称为极化方向,极化方向与传播方向共同构成了极 化面。在通信链路中,只有接收机天线与被接收信号的极化形式匹配时,才能有效的接收信号,如果接收机天线…

IoTDB 入门教程 基础篇⑨——TsFile导入导出工具

文章目录 一、前文二、准备2.1 准备导出服务器2.2 准备导入服务器 三、导出3.1 导出命令3.2 执行命令3.3 tsfile文件 四、导入4.1 上传tsfile文件4.2 导入命令4.3 执行命令 五、查询六、参考 一、前文 IoTDB入门教程——导读 数据库备份与迁移是数据库运维中的核心任务&#xf…

平台介绍-All in One

我们平台的口号也是All in One&#xff0c;在一个平台上实现一个企业内部的所有应用&#xff0c;统一的操作模式&#xff0c;统一的权限体系&#xff0c;统一界面&#xff0c;我们也坚信这是未来企业信息化的方向。同样喊这个口号的飞书败了&#xff0c;能说明这条路错了吗&…

正在载入qrc文件 指定的qrc文件无法找到。您想更新这个文件的位置么?

打开Qt的ui文件&#xff0c;弹出提示框 如果需要用到qrc文件&#xff0c;选择Yes&#xff0c;再选择qrc文件所在的位置&#xff1b;如果不需要qrc文件&#xff0c;可以选择No&#xff0c;然后用普通文本编辑器打开&#xff0c;将“ <resources> <include location&q…

Docker高频使用命令

一、Docker常用命令总结 1.镜像命令管理 指令描述ls列出镜像build构建镜像来自Dockerfilehoistory查看历史镜像inspect显示一个或多个镜像的详细信息pull从镜像仓库拉取镜像push推送一个镜像仓库rm移除一个或多个镜像prune一处未使用的镜像&#xff0c;没有被标记或被任何容器…

ArcGIS软件:地图投影的认识、投影定制

这一篇博客介绍的主要是如何在ArcGIS软件中查看投影数据&#xff0c;如何定制投影。 1.查看地图坐标系、投影数据 首先我们打开COUNTIES.shp数据&#xff08;美国行政区划图&#xff09;&#xff0c;并点击鼠标右键&#xff0c;再点击数据框属性就可以得到以下的界面。 我们从…

PHP 反序列化

一、PHP 序列化 1、对象的序列化 <?php class people{public $nameGaming;private $NationLiyue;protected $Birthday12/22;public function say(){echo "老板你好呀&#xff0c;我是和记厅的镖师&#xff0c;叫我嘉明就行&#xff0c;要运货吗你&#xff1f;"…