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是用来确认 ...
随机推荐
- NEST health与settings
/// <summary> /// 创建Idx,并设置分片和副本 /// </summary> public void Settings() { var response = ...
- Ubuntu 18.04 LTS版本 谷歌拼音输入法安装
为何安装? 自带IBUS框架对中文支持不稳定 采用对中文支持稳定的fcitx框架 如何安装? 步骤如下: 卸载自带IBUS框架 命令:sudo remove ibus 安装fcitx框架 ...
- RAS非对称加密
加解密密钥不一致,一般私钥不公开,使用公钥加密,私钥解密,使用私钥加密,公钥可以解密. java代码 import javax.crypto.Cipher; import java.security. ...
- 安恒pwn魔法
魔法这是比较基础的一道栈溢出: 首先看下开启的防护机制 Checksec magicc发现只有nx防护 我们载入ida发现溢出点 Buf实际溢出空间为0x16,构造exp import time fr ...
- error: unknown filesystem; grub rescue
我的电脑是win10+ubumtu双系统 在一次windows更新之后,系统无法进入win10和linux系统,出现如图错误 解决方案1: 大部分中文博客的解决方案:这里有个更加详细的: https: ...
- java线程的生命周期及五种基本状态
一.线程的生命周期及五种基本状态 关于Java中线程的生命周期,首先看一下下面这张较为经典的图: 上图中基本上囊括了Java中多线程各重要知识点.掌握了上图中的各知识点,Java中的多线程也就基本上掌 ...
- Java中重载(overloading)和重写(Overriding)的区别
一:方法的重载 (1)方法重载指在类中定义方法名相同,参数不同的不同的多个方法(返回值类型可随意,不能以返回类型作为重载函数的区分标准). 参数不同表现: 1.参数的个数不同 2.参数的类型不同 3. ...
- Docker安装与部署
安装Docker: 查看你当前的内核版本: uname -r 更新yum包: sudo yum update 卸载旧版本(如果安装过旧版本的话): sudo yum remove docker doc ...
- 关于linux的档案随笔
刚才在看鸟哥的linux的私房菜,然后看到的部分是关于linux的档案配置部分,之前就强调过,在linux中所有的一切都是以档案的形式存在的,不过不同的文件有一定的区别,linux中是有副档案这个说法 ...
- react native 手动打包jsbundle文件
1 在项目目录/android/app/src/main下建一个文件夹assets 2 react-native bundle --platform android --dev false --ent ...