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是用来确认 ...
随机推荐
- NetworkInterface网速监测
private NetworkInterface[] nicArr; //网卡集合 private Timer timer; //计时器 public MainWindow() { Initializ ...
- 【转载】Asp.net网站安全:去除网站根目录下的备份文件防止代码泄露
很多网站运维人员在更新网站版本的时候,喜欢直接在网站目录文件夹中直接压缩原来的网站文件,如果这个备份压缩文件没有移动出去,这样是非常不安全的,有些网站攻击者可能会尝试访问你网站下有没有对应名字的压缩备 ...
- javascript创建一个基于对象的栈结构
上篇博客介绍了基于数组创建一个栈,这是用对象创建一个栈 s1.声明一个Stack类 class Stack { constructor() { this.count = 0; this.items = ...
- Core Animation笔记(变换)
1.仿射变换 CGAffineTransformMakeScale : CGAffineTransformMakeTranslation CGAffineTransformMakeRotation(C ...
- linux 内网时间同步配置
在工作中,内网环境机器的时间会有所差异,在某些测试环境下需要一毫秒都不允许出现误差,但又不想同步外网时间,那我们可以选择一台机器作为时间服务器来供其他机器进行时间同步,例如每隔1分钟同步一次时间. 一 ...
- SQLSEVER导出 xml文件
各种都可以参照: 链接:https://wenku.baidu.com/view/778f794bfe4733687e21aa90.html 怎样把SQL Server里的某个表的数据导出成XML文件 ...
- @PropertySources和@ImportReSources注解
修改默认加载的配置文件,加载指定的配置文件. @PropertySources 格式:@PropertySources(value={"classpath:xxx.xxx"}) @ ...
- python接口自动化13-data和json参数傻傻分不清
前言 在发post请求的时候,有时候body部分要传data参数,有时候body部分又要传json参数,那么问题来了:到底什么时候该传json,什么时候该传data? 一.识别json参数 1.在前面 ...
- MongonDB 知识
配置 vi mongodb.conf dbpath=/usr/local/mongodb/data/ logpath=/usr/local/mongodb/data/mongodb.log port ...
- [LeetCode] 0155. Min Stack 最小栈 & C++Runtime加速
题目 Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. ...