Complete the Projects
F1. Complete the Projects (easy version)
F2. Complete the Projects (hard version)
参考:Complete the Projects
简单说就是当 b>=0 是肯定是 a 小的优先的,需要注意的就是 b<0,的情况,结论:a+b 大的优先(证明看参考博客)
需要用到的算法:贪心和 dp
代码(只贴 F2 的了,F1 改一点点就行):
// Created by CAD on 2019/8/14.
#include <bits/stdc++.h>
#define fi first
#define se second
#define inf 0x3f3f3f3f
using namespace std;
using pii=pair<int, int>;
using piii=pair<pair<int, int>, int>;
using ll=long long;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
vector<pii>pos,neg;
int n,r;
cin>>n>>r;
for(int i=1,a,b;i<=n;++i)
{
cin >> a >> b;
if(b>=0)
pos.push_back({a,b});
else neg.emplace_back(a+b,a);
}
sort(pos.begin(),pos.end());
sort(neg.begin(),neg.end());
reverse(neg.begin(),neg.end());
int cnt=0;
for(auto p:pos)
if(r<p.fi) break;
else r+=p.se,cnt++;
vector<int>dp(r+1,-inf);
dp[r]=cnt;
for(auto p:neg)
{
int a=p.se,b=p.fi-p.se;
for(int i=max(a,-b);i<=r;++i)
dp[i+b]=max(dp[i+b],dp[i]+1);
}
for(int i=0;i<=r;++i)
cnt=max(cnt,dp[i]);
cout<<cnt<<endl;
}
Complete the Projects的更多相关文章
- CF1203F2 Complete the Projects (hard version)(结论+背包+贪心)
题目 做法 对于加分的直接贪心 而掉分的用排序后的背包动规 假设有两个物品\((a_1,b_1)(a_2,b_2)\) 选第一个物品后无法选择第二个物品,假设开始值为\(r\):\(r>a_1, ...
- Codeforces 1203F2. Complete the Projects (hard version)
传送门 首先对于 $b>0$ 的工作显然有个贪心,把 $b>0$ 的按 $a$ 从小到大排序 把能做的都做了,然后得到一个最大等级 剩下就是考虑 $b<0$ 的工作了,看到数据显然可 ...
- Codeforces1203F2. Complete the Projects (hard version) (贪心+贪心+01背包)
题目链接:传送门 思路: 对于对rating有提升的项目,肯定做越多越好,所以把$b_{i} >= 0$的项目按rating要求从小到大贪心地都做掉,得到最高的rating记为r. 对于剩余的$ ...
- Codeforces 1203F1 Complete the Projects (easy version)
cf题面 Time limit 2000 ms Memory limit 262144 kB 解题思路 看见这题觉得贪心可做,那就贪吧.(昨天真是贪心的一天,凌晨才被这两道贪心题虐,下午多校又来,感觉 ...
- Codeforces Round #579 (Div. 3) Complete the Projects(贪心、DP)
http://codeforces.com/contest/1203/problem/F1 Examples input 1 - - output 1 YES input 2 - - output 2 ...
- P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1
P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1 May ...
- 微软职位内部推荐-Senior Data Scientist
微软近期Open的职位: Extracting accurate, insightful and actionable information from data is part art and pa ...
- Codeforces Round #579 (Div. 3)
Codeforces Round #579 (Div. 3) 传送门 A. Circle of Students 这题我是直接把正序.逆序的两种放在数组里面直接判断. Code #include &l ...
- Gerrit - 代码评审工具Gerrit简介与安装
1 - 前言 Code Review 代码评审是指在软件开发过程中,对源代码的系统性检查,改进代码质量,查找系统缺陷,保证软件总体质量和提高开发者自身水平. 简单的说,Code Review是用来确认 ...
随机推荐
- Oracle - 实现MySQL的limit功能
MySQL的limit功能是获取指定行数的数据,Oracle没有这个limit,但是有其它方法. oracle数据库不支持mysql中limit功能,但可以通过rownum来限制返回的结果集的行数,r ...
- Fortify漏洞之Insecure Randomness(不安全随机数)
继续对Fortify的漏洞进行总结,本篇主要针对 Insecure Randomness 漏洞进行总结,如下: 1.Insecure Randomness(不安全随机数) 1.1.产生原因: 成弱 ...
- UCOSIII互斥信号量
互斥信号量可以解决优先级反转问题 优化后现象 优化方法:L和H等待同一个信号量的时候,将L任务优先级提至H相同优先级 实验举例 void start_task(void *p_arg) { OS_CR ...
- QTableWidget数据表格
void setRowHeight(int row, int height); //行高 void setVerticalHeaderLabels(const QStringList &lab ...
- Flask之threading.loacl方法
一.threading.loacl方法 import threading import time class Foo: pass foo = Foo() def func(num): foo.num ...
- flutter入门开发的一些坑
flutter入门开发的一些坑 很久没写博客了,最近在准备物联网比赛,顺便抽出时间学习了一下flutter,花了近2周完成了一个查看博客博文的一个小的APPdemo,随便截了两张图,如下: 首页 博客 ...
- [ipsec][strongswan] VirtualPN隧道网络加速FEC(forward error correction)
引用 跟一个网友就有关IPsec的网络加速以及降低延迟等问题进行了一些讨论,并总结了一写粗浅的看法. 因为FEC的资料并不多,所以分享出来,希望能被有需要的人看见:) 先说一下FEC. 我们使用ips ...
- 使用Eclipse Memory Analyzer进行内存泄漏分析
一.准备工作 1)工具下载: http://www.eclipse.org/mat/downloads.php 可以选择eclipse插件的方式安装 http://download.eclipse.o ...
- TODO的作用及如何使用
https://blog.csdn.net/jerry11112/article/details/82966142 文章标题:[C#]TODO的作用 可以方便后续找到要做的功能点.
- 使用Arduino开发板制作交流电压表
在本文中,我们将使用Arduino开发板制作一个交流电压测量装置,测量我们家中交流电源的电压.我们将在Arduino IDE的串行监视器上打印输出该电压,并在万用表上显示出来. 制作数字电压表比模拟电 ...