http://codeforces.com/contest/1203/problem/F1

Examples

input 1

 -
-
output 1
YES
input 2
 -
-
output 2
YES
input 3

 -

 -
output 3
YES
input 4

 -
 
output 4
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

input 1

 -
-
output 1
 
input 2
 -
- -
output 2
 
input 3
 -
output 3

 

先粘题解,以后再填坑

 #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)的更多相关文章

  1. Codeforces Round #317 (Div. 2) D Minimization (贪心+dp)

    D. Minimization time limit per test  2 seconds memory limit per test  256 megabytes input  standard ...

  2. Codeforces Round #579 (Div. 3)

    Codeforces Round #579 (Div. 3) 传送门 A. Circle of Students 这题我是直接把正序.逆序的两种放在数组里面直接判断. Code #include &l ...

  3. Codeforces Round #367 (Div. 2) C. Hard problem(DP)

    Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...

  4. Codeforces Round #579 (Div. 3) 套题 题解

    A. Circle of Students      题目:https://codeforces.com/contest/1203/problem/A 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...

  5. 【cf比赛练习记录】Codeforces Round #579 (Div. 3)

    思考之后再看题解,是与别人灵魂之间的沟通与碰撞 A. Circle of Students 题意 给出n个数,问它们向左或者向右是否都能成一个环.比如样例5是从1开始向左绕了一圈 [3, 2, 1, ...

  6. Codeforces Round #579 (Div. 3) 题解

    比赛链接:https://codeforc.es/contest/1203/ A. Circle of Students 题意:\(T\)组询问,每组询问给出\(n\)个数字,问这\(n\)个数字能否 ...

  7. 双指针(最大删除子串)Codeforces Round #579 (Div. 3)--Remove the Substring (hard version)

    题目链接:https://codeforces.com/contest/1203/problem/D2 题意: 给你S串.T串,问你最长删除多长的子串使得S串里仍然有T的子序列. 思路: 想了好久,先 ...

  8. Codeforces Round #579 (Div. 3)D(字符串,思维)

    #include<bits/stdc++.h>using namespace std;char s[200007],t[200007];int last[200007][27],nxt[2 ...

  9. Codeforces Round #579 (Div. 3) B Equal Rectangles、C. Common Divisors

    B Equal Rectangles 题意: 给你4*n个数,让你判断能不能用这个4*n个数为边凑成n个矩形,使的每个矩形面积相等 题解: 原本是想着用二分来找出来那个最终的面积,但是仔细想一想,那个 ...

随机推荐

  1. 【数据库】SQL 关系代数

    环境:MySQL ID:MySQL WorkBench 6.3 CE 实现以下有点难度的关系除法. 先给定义: 除运算是同时从关系的水平方向和垂直方向进行运算.给定关系R(X,Y)和S(Y,Z),X. ...

  2. 3DES 原理

    3DES的原理: 加密阶段:用密钥1加密->用密钥2解密->用密钥3加密 解密阶段:用密钥3解密->用密钥2加密->用密钥1解密 版权声明:本文为博主原创文章,未经博主允许不得 ...

  3. 题目(或游戏)流程控制器上传到GitHub

    题目控制系统 1 支持 题目按相同的个数分组 2 支持 pause resume 3 支持 每题限定时间 4 支持 支持对计时器进行回调 5 支持 在全流程开始,全流程结束,每组开始,每组结束,每题开 ...

  4. 洛谷 P1968 美元汇率

    题目传送门 解题思路: 一道很简单的DP AC代码: #include<iostream> #include<cstdio> using namespace std; int ...

  5. Git 报错:fatal: refusing to merge unrelated histories

    背景:[接上篇git push 出错的随笔]当 pull 远端仓库到本地的时候,出现以下错误: 错误情况: 出错原因:主要原因还是在于本地仓库和远程仓库实际上是独立的两个仓库,假如我之前是直接以 cl ...

  6. 把Android studio的日志导入目标文件中

    最好是在Android studio的命令行工具中进行命令操作. adb logcat -v time > /Users/z/log.txt adb logcat -v time > /U ...

  7. UML-用例关联

    1.用例关联:就是各个用例之间的关系,分3种关系分别是:包含关系.扩展关系.泛化关系. 2.包含关系 1).示例 2).使用场景 A.用例在其他用例中重复使用 B.用例非常复杂冗长,将其分解为子单元便 ...

  8. [极客大挑战 2019]PHP

    0x00知识点 1:直接扫描目录得到网站源码. 2:public.protected与private在序列化时的区别 protected 声明的字段为保护字段,在所声明的类和该类的子类中可见,但在该类 ...

  9. Java中常用的API(一)——Object

    概述 如果要问Java为什么是用起来非常舒服的语言,那很大一部分的功劳就是JavaAPI的.API定义了许多封装好的类和方法供我们使用,来处理特定的问题,所以学习常用的API是非常重要的. 同时,面向 ...

  10. zabbix使用短信猫实现报警

    因为公司运维的对象是政府单位,所以在实际的监控过程中无法连接到外网,所以最后报警选择的媒介是短信猫,下边就是具体的实施过程. 一.面临的问题 因为手头上的设备是串口的短信猫,但是zabbix serv ...