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. zuul网关配置

    静态路由:通过url匹配映射地址进行静态路由(只会把到达zuul网关的请求按照发送,并把匹配请求地址 /common-service/ ->http://localhost:9001/) zuu ...

  2. Flink:动态表上的连续查询

    用SQL分析数据流 越来越多的公司在采用流处理技术,并将现有的批处理应用程序迁移到流处理或者为新的应用设计流处理方案.其中许多应用程序专注于分析流数据.分析的数据流来源广泛,如数据库交易,点击,传感器 ...

  3. css3 实现渐变边框

    (1)一个渐变的底边线border:1px solid transparent;border-image: -webkit-linear-gradient(right, #FF9848,#FF2A2B ...

  4. c++ rand随机数生成(随机种子设置)

    需求:每次初始化不同的随机数 1.默认 //这样用每次都会产生相同数字 #include <stdlib.h> #include <stdio.h> #define N 10 ...

  5. Linux简介和环境的搭建

    Linux的学习方向 网络服务器 嵌入式程序开发 Linux的设计哲学:一切皆文件 常用命令:cd 切换目录sudo shutdown -h now 关机命令sudo reboot 重启sudo ro ...

  6. Python自学之路---Day01

    目录 Python自学之路---Day01 注释 单行注释 多行注释 print()函数 语法 参数 实例 input()函数 语法 参数 实例 查看Python的关键字 代码 变量与常量 变量 如何 ...

  7. Map 查找表操作

    package seday13; import java.util.HashMap; import java.util.Map; /** * @author xingsir * java.util.M ...

  8. python刷LeetCode:2.两数相加

    难度等级:中等 题目描述: 给出两个 非空 的链表用来表示两个非负的整数.其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字. 如果,我们将这两个数相加起来,则会返 ...

  9. Python—数据结构——链表

    数据结构——链表 一.简介 链表是一种物理存储上非连续,数据元素的逻辑顺序通过链表中的指针链接次序,实现的一种线性存储结构.由一系列节点组成的元素集合.每个节点包含两部分,数据域item和指向下一个节 ...

  10. Windows下对文件夹下所有图片批量重命名(附C++,python,matlab代码)

    https://blog.csdn.net/u011574296/article/details/72956446: Windows下对文件夹下所有图片批量重命名(附C++,python,matlab ...