Team Composition: Programmers and Mathematicians 贪心(800)
题意 :
- 给p的个数和m的个数,要求4个一组,且每组中p和m的个数≥1\geq1≥1,求最多分多少组
思路 :
- 令p≤mp \leq mp≤m,设差值d=m−pd=m-pd=m−p,先尽量把差值抵消,每次p−1,m−3,d−2p-1,m-3,d-2p−1,m−3,d−2,组成min(d/2,min(p,m/3))min(d/2,min(p,m/3))min(d/2,min(p,m/3))组
- 然后
差值小于2
,每次就可以两个数字都分别取两个,贪心地保证a和b都尽量取完
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <unordered_set>
#include <math.h>
using namespace std;typedef long long ll;
typedef pair<int, int> PII;#define endl '\n'
#define fi first
#define se second
#define push_back
#define rep(i, l, r) for (ll i = l; i <= r; i ++ )void solve()
{int p, m; cin >> p >> m;if (p > m) swap(p, m);int d = m - p;int ans = min(d / 2, min(p, m / 3));p -= ans, m -= 3 * ans;ans += min(p / 2, m / 2);cout << ans << endl;
}int main()
{cin.tie(nullptr) -> sync_with_stdio(false);int _;cin >> _;while (_ -- )solve();return 0;
}
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <unordered_set>
#include <math.h>
using namespace std;typedef long long ll;
typedef pair<int, int> PII;#define endl '\n'
#define fi first
#define se second
#define push_back
#define rep(i, l, r) for (ll i = l; i <= r; i ++ )void solve()
{int p, m; cin >> p >> m;if (p > m) swap(p, m);int d = m - p;if (p < d / 2) cout << p << endl;elsecout << d / 2 + (p - d / 2) / 2 << endl;
}int main()
{cin.tie(nullptr) -> sync_with_stdio(false);int _;cin >> _;while (_ -- )solve();return 0;
}
Team Composition: Programmers and Mathematicians 贪心(800)相关推荐
- Divan and a Store 贪心(800)
题意 : 给n个物品的价格,有k元,以及购买物品价格的范围,问最多能买几个物品 思路 : 直接贪心 #include <iostream> #include <algorithm&g ...
- CF756div3 vp
又被薄纱了,rk就不放了,好丢人QwQ Dashboard - Codeforces Round 756 (Div. 3) - Codeforces A. Make Even 小分类讨论 题意: 给定 ...
- Codeforces Round #756 (Div. 3)
Codeforces Round #756 (Div. 3) A. Make Even 思路:如果末尾是偶数,不需要操作:如果开头是偶数,一次操作,即全翻转:如果开头和末尾都是 奇数,判断里面是否有偶 ...
- 北邮OJ 2016网预 - Saber's Conjecture
时间限制 1000 ms 内存限制 65536 KB 题目描述 In a parallel universe, young Saber-chan does not have a humongous a ...
- npm中node更新_如何在Node中管理NPM和功能时保持理智
npm中node更新 by Ted Gross 泰德·格罗斯(Ted Gross) 如何在Node中管理NPM和功能时保持理智 (How to keep your sanity while manag ...
- spring 演变_团队的演变
spring 演变 Editor's Note: Your team will change whether you like it or not. People will come and go. ...
- ISTQB TM考点总结
ISTQB Test Manager考试总结 1.Testing Process 9个考点 1.2.1 k4 1.3.1 k3 1.3.2 k2 1.4.1 k3 1.5.1 k3 1.6.1 k3 ...
- OCJP(1Z0-851) 模拟题分析(四)
Exam : 1Z0-851 Java Standard Edition 6 Programmer Certified Professional Exam 以下分析全都是我自己分析或者参考网上的,定有 ...
- 《乔布斯传》英文原著重点词汇笔记(十四)【 chapter thirteen】
Building the Mac:The Jounery Is the Reward 之 Competition 1. established adj.知名的, ...
最新文章
- oracle求某个数的阶乘,Oracle SQL实现阶乘的几个方法
- 一个简单自激振荡器电路分析
- linux之source
- 将窗体显示在 PageControl 上。
- 在线聊天javascript代码
- Cannot add product to Opportunity in Fiori - RFC error
- 我的 2020 年个人总结
- MySQL 5.7.18的安装与主从复制
- 学python后到底能干什么-学Python后到底能干什么
- XlsxWriter的使用
- 自动驾驶各大传感器介绍-硬件篇
- 【 信息搜集的内容,信息搜集的方法,信息搜集的工具,信息搜集结果的利用等】
- java获取method_从Method中获取完整类名和方法名
- 跑revit计算机硬件要求,什么样的电脑能流畅跑Revit?Revit对电脑配置要求
- UA MATH524 复变函数 验证一个函数是否为调和函数
- FlinkX数据同步
- 家庭教育:怎样安慰不想上学的人
- 基于proteus的51单片机仿真实例二、关于proteus
- 纳米数据,足球比分,赛事数据接口api,足球数据接口
- 记一次Windows10 home版文件共享步骤及问题处理
热门文章
- [三代] 获取BADI对象的两种方法
- SAP 货物移动 BAPI 的简单使用 BAPI_GOODSMVT_CREATE
- SAP调用WSDL报错,求解!
- sap中Excel的模版上传和下载
- ALV中调用Excel inplace时没能传递数据实例解决
- BAPI_GOODSMVT_CREATE的几个应用
- asp.net ajax 怎么获取前端ul li_字节前端提前批面试题:触发了几次回流几次重绘...
- spark入门_Spark技术入门——配置部署、SparkSQL应用
- 如何利用python3创建数据表_python3创建表及表数据;
- 五相同步电机matlab模型,五相永磁同步电机空间矢量PWM控制系统MATLAB仿真