当前位置: 首页 > news >正文

AtCoder Beginner Contest 374 E题 Sensor Optimization Dilemma 2(二分,贪心)

题目链接

AtCoder Beginner Contest 374 E

思路

我们很容易想到直接二分答案。

因为机器 s i s_{i} si t i t_{i} ti每天最多可以加工 100 100 100个产品。因此,对于 s i s_{i} si t i t_{i} ti中性价比低的那一个不会选太多。

因此我们可以直接枚举性价比低的那一台机器的数量,贪心地 c h e c k check check即可。

代码

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e2 + 5;
const int mod = 998244353;
const int inf = 0x3f3f3f3f3f3f3f3f;
int n, x;
int a[N], p[N], b[N], q[N];
bool check(int w)
{int cnt = 0;for (int i = 1; i <= n; i++){int res = 1e9;for (int j = 0; j <= 10000; j++){if (a[i] * q[i] > b[i] * p[i]){// b更低int op = w - j * b[i];op = max(op, 0ll);int sum = j * q[i] + (op / a[i] + (op % a[i] != 0)) * p[i];res = min(res, sum);}else{int op = w - j * a[i];op = max(op, 0ll);int sum = j * p[i] + (op / b[i] + (op % b[i] != 0)) * q[i];res = min(res, sum);}}cnt += res;}return cnt <= x;
}
void solve()
{cin >> n >> x;for (int i = 1; i <= n; i++){cin >> a[i] >> p[i] >> b[i] >> q[i];}int low = 0, high = 1e9;while (low < high){int mid = low + high + 1 >> 1;if (check(mid)){low = mid;}elsehigh = mid - 1;}cout << low << endl;
}
signed main()
{ios::sync_with_stdio(false);cin.tie(0), cout.tie(0);int test = 1;// cin >> test;for (int i = 1; i <= test; i++){solve();}return 0;
}

http://www.mrgr.cn/news/43559.html

相关文章:

  • Qt教程(002):Qt项目创建于框架介绍
  • 保险丝基础知识
  • 【深度学习】矩阵操作万能函数 einsum-爱因斯坦求和
  • 如何使用CMD命令启动应用程序(二)
  • C0015.Clion中开发C++时,连接Mysql数据库方法
  • 【英特尔IA-32架构软件开发者开发手册第3卷:系统编程指南】2001年版翻译,1-1
  • 《python语言程序设计》2018版第8章19题几何Rectangle2D类(下)-头疼的几何和数学
  • 传感器模块编程实践(三)舵机+超声波模块融合DIY智能垃圾桶模型
  • 常见的基础系统
  • 今天学的Word小技巧——批量设置图片格式,批量让题注居中
  • 软考系统分析师知识点二:经济管理
  • 每日一道算法题——二分查找
  • clickhouse数据字典
  • 使用SpringBoot自定义注解+拦截器+token机制,实现接口的幂等性
  • 【go入门】流程控制语句
  • 51c视觉~CV~合集3
  • 基于Java的GeoTools对Shapefile文件属性信息深度解析
  • C语言进阶版第16课—自定义类型:结构体
  • webserver
  • 网络基础知识笔记(五)接口管理