Codeforces Round #579 (Div. 3) Complete the Projects(贪心、DP)
http://codeforces.com/contest/1203/problem/F1

Examples
-
-
YES
-
-
YES
- -
YES
-
NO
Note
In the first example, the possible order is: 1,2,3.
In the second example, the possible order is: 2,3,1.
In the third example, the possible order is: 3,1,4,2.
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <math.h>
const int INF=0x3f3f3f3f;
typedef long long LL;
const int mod=1e9+;
const double PI=acos(-);
const int maxn=1e5+;
using namespace std; struct node1
{
int a;
int b;
}zheng[]; struct node2
{
int a;
int b;
}fu[]; int n1,n2; bool cmp1(node1 x,node1 y)
{
return x.a<y.a;
} bool cmp2(node2 x,node2 y)
{
if(x.a+x.b!=y.a+y.b)
return x.a+x.b>y.a+y.b;
else
return x.b>y.b;
} int main()
{
int n,r;
scanf("%d %d",&n,&r);
for(int i=;i<=n;i++)
{
int x,y;
scanf("%d %d",&x,&y);
if(y<)
{
fu[n2].a=x;
fu[n2].b=y;
n2++;
}
else
{
zheng[n1].a=x;
zheng[n1].b=y;
n1++;
}
}
sort(zheng,zheng+n1,cmp1);
for(int i=;i<n1;i++)
{
if(r<zheng[i].a)
{
printf("NO\n");
return ;
}
r+=zheng[i].b;
}
sort(fu,fu+n2,cmp2);
for(int i=;i<n2;i++)
{
if(r<fu[i].a)
{
printf("NO\n");
return ;
}
r+=fu[i].b;
}
if(r<)
printf("NO\n");
else
printf("YES\n");
return ;
}
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
#define endl '\n' const int maxn = ;
int dp[];
pair<int, int> a[maxn];
queue<int> q; int main(){
ios::sync_with_stdio(false);
cin.tie(NULL); int n, r;
cin >> n >> r; for(int i = ; i < n; i++){
cin >> a[i].first >> a[i].second;
} sort(a, a + n); int l = , sum = r, ans = ;
for(; l < n && a[l].first <= sum; l++){
if(a[l].second >= ){
q.push(l);
ans++;
}
} while(!q.empty()){
int c = q.front();
q.pop(); sum += a[c].second; for(; l < n && a[l].first <= sum; l++){
if(a[l].second >= ){
q.push(l);
ans++;
}
}
} sort(a, a + l, [&](pair<int, int> f, pair<int, int> g){
return f.first + f.second > g.first + g.second;
});
dp[] = ans; for(int i = ; i < l; i++){
if(a[i].second >= ) continue;
int y = -a[i].second; for(int j = sum - max(y, a[i].first); j >= ; j--){
dp[j + y] = max(dp[j + y], dp[j] + );
ans = max(ans, dp[j + y]);
}
} cout << (ans == n ? "YES" : "NO") << endl; return ;
}
http://codeforces.com/contest/1203/problem/F2

Examples
-
-
-
- -
-
先粘题解,以后再填坑
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <queue>
#include<bits/stdc++.h>
using namespace std; #define PI acos(-1)
#define hell 1000000007
#define HELL 998244353
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define ADD(a,b,c) ((a)%c+(b)%c)%c
#define SUB(a,b,c) ((a)%c-(b)%c+c)%c
#define MUL(a,b,c) (((a)%c)*((b)%c))%c
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
#define endl "\n"
#define out(n) cout<<n<<" "
#define outl(n) cout<<n<<endl
#define line cout<<endl
#define bug(n) {outl(n);return;}
#define N 105
ll n,r,dp[N][];
pll a[N];
bool comp(pll a, pll b){
if(a.se>&&b.se>)return a.fi<b.fi;
if(a.se>||b.se>)return a.se>;
return a.fi+a.se>b.fi+b.se;
}
ll fun(ll i, ll r){
if(dp[i][r]!=-)return dp[i][r];
if(i==n+)return ;
ll ans=fun(i+,r);
if(r>=a[i].fi&&r>=-a[i].se)ans=max(ans,+fun(i+,r+a[i].se));
return dp[i][r]=ans;
}
void solve(){
cin>>n>>r;
mset(dp,-);
rep(i,,n+)cin>>a[i].fi>>a[i].se;
sort(a+,a+n+,comp);
bug(fun(,r));
}
void prep(){ }
int main(){
io;
ll t=;
// cin>>t;
prep();
fix();
while(t--)
solve();
return ;
}
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
#define endl '\n' const int maxn = ;
int dp[];
pair<int, int> a[maxn];
queue<int> q; int main(){
ios::sync_with_stdio(false);
cin.tie(NULL); int n, r;
cin >> n >> r; for(int i = ; i < n; i++){
cin >> a[i].first >> a[i].second;
} sort(a, a + n); int l = , sum = r, ans = ;
for(; l < n && a[l].first <= sum; l++){
if(a[l].second >= ){
q.push(l);
ans++;
}
} while(!q.empty()){
int c = q.front();
q.pop(); sum += a[c].second; for(; l < n && a[l].first <= sum; l++){
if(a[l].second >= ){
q.push(l);
ans++;
}
}
} sort(a, a + l, [&](pair<int, int> f, pair<int, int> g){
return f.first + f.second > g.first + g.second;
});
dp[] = ans; for(int i = ; i < l; i++){
if(a[i].second >= ) continue;
int y = -a[i].second; for(int j = sum - max(y, a[i].first); j >= ; j--){
dp[j + y] = max(dp[j + y], dp[j] + );
ans = max(ans, dp[j + y]);
}
} cout << ans << endl; return ;
}
Codeforces Round #579 (Div. 3) Complete the Projects(贪心、DP)的更多相关文章
- Codeforces Round #317 (Div. 2) D Minimization (贪心+dp)
D. Minimization time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #579 (Div. 3)
Codeforces Round #579 (Div. 3) 传送门 A. Circle of Students 这题我是直接把正序.逆序的两种放在数组里面直接判断. Code #include &l ...
- Codeforces Round #367 (Div. 2) C. Hard problem(DP)
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...
- Codeforces Round #579 (Div. 3) 套题 题解
A. Circle of Students 题目:https://codeforces.com/contest/1203/problem/A 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...
- 【cf比赛练习记录】Codeforces Round #579 (Div. 3)
思考之后再看题解,是与别人灵魂之间的沟通与碰撞 A. Circle of Students 题意 给出n个数,问它们向左或者向右是否都能成一个环.比如样例5是从1开始向左绕了一圈 [3, 2, 1, ...
- Codeforces Round #579 (Div. 3) 题解
比赛链接:https://codeforc.es/contest/1203/ A. Circle of Students 题意:\(T\)组询问,每组询问给出\(n\)个数字,问这\(n\)个数字能否 ...
- 双指针(最大删除子串)Codeforces Round #579 (Div. 3)--Remove the Substring (hard version)
题目链接:https://codeforces.com/contest/1203/problem/D2 题意: 给你S串.T串,问你最长删除多长的子串使得S串里仍然有T的子序列. 思路: 想了好久,先 ...
- Codeforces Round #579 (Div. 3)D(字符串,思维)
#include<bits/stdc++.h>using namespace std;char s[200007],t[200007];int last[200007][27],nxt[2 ...
- Codeforces Round #579 (Div. 3) B Equal Rectangles、C. Common Divisors
B Equal Rectangles 题意: 给你4*n个数,让你判断能不能用这个4*n个数为边凑成n个矩形,使的每个矩形面积相等 题解: 原本是想着用二分来找出来那个最终的面积,但是仔细想一想,那个 ...
随机推荐
- Maven - 构建生命周期、阶段、目标
版权所有,未经授权,禁止转载 章节 Maven – 简介 Maven – 工作原理 Maven – Repository(存储库) Maven – pom.xml 文件 Maven – 依赖管理 Ma ...
- Mybatis 持久化,持久层
持久化 持久化是将程序数据在持久状态和瞬时状态间转换的机制. 即把数据(如内存中的对象)保存到可永久保存的存储设备中(如磁盘).持久化的主要应用是将内存中的对象存储在数据库中,或者存储在磁盘文件中.X ...
- redis官网下载自动安装脚本
注释:使用方法为 # ./redis.sh version ----version为官网版本号 #!/bin/bashversion=$1serverurl='download. ...
- Unity3D一些基本的概念和一些基本操作
场景:整个游戏由场景组成,一个游戏至少要有一个场景,如果把所有的游戏画面放在一个场景里也是可以的,如果游戏非常非常的大,如果所有的东西都放到一个场景里那么结构就不是那么清晰了而且处理起来就会麻烦一些, ...
- UVALive 4670 AC自动机
第二道AC自动机的题目了,之前参考的是网上一个博客算法,不怎么好,难写而且占空间 后来参照大白书做的这题,代码简洁多了 #include <iostream> #include <c ...
- 京东云入选2019年度TOP100全球软件案例 新一代服务治理框架加速行业落地
11月14日-17日, 2019TOP100全球软件案例研究峰会(TOP100summit)在北京国家会议中心举办.Top100summit是科技界一年一度的案例研究峰会,每年会秉承"从用户 ...
- 201712-2 游戏 Java
思路: 第一感觉有点像约瑟夫环.想到用队列解决比较好理解 import java.util.LinkedList; import java.util.Queue; import java.util.S ...
- Dynamics CRM - 在 C# Plugin 里以 System Administrator 权限来更新 Entity
场景说明: 1.在使用 CRM 系统时,经常会有需要在某个 Entity 下对其他 Entity 的 Record 进行更新,或者在 post 中对自身进行更新,这里就需要用到 SDK 上的 upda ...
- Python说文解字_杂谈01
1. Python在Ubuntu下面下载Python 2. 安装依赖包 sudo apt-get update sudo apt-get install build-essential python- ...
- ModernRNN
GRU RNN存在的问题:梯度较容易出现衰减或爆炸(BPTT) ⻔控循环神经⽹络:捕捉时间序列中时间步距离较⼤的依赖关系 RNN: \[ H_{t} = ϕ(X_{t}W_{xh} + H_{t-1} ...