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. web网页外部分享到微信、朋友圈、扣扣、微博等功能、自动生成二维码等

    1.这里重中之重是分享到微信:web端网页通常是没有权限分享过去的 所以用: weixin://dl/business/?ticket=ta428dhj739hg3efe6e  但是这个ticket真 ...

  2. mysql初始化数据库建表脚本

    set names utf8; set global validate_password.policy=LOW;set global validate_password.length=6;CREATE ...

  3. MyBatis:分页的实现

    日志工厂 思考:我们在测试SQL的时候,要是能够在控制台输出 SQL 的话,是不是就能够有更快的排错效率? 如果一个 数据库相关的操作出现了问题,我们可以根据输出的SQL语句快速排查问题. 对于以往的 ...

  4. pandas dataframe取差集:删掉已存在的数据,保留未插入的数据

    适用场景: 插入数据到mysql中,中途中断,导致部分数据未插入成功.避免下次插入时插入了重复的数据. 思路: 1.读取已插入的数据, 2.读取全部数据(包含已插入和未插入的), 3.将已插入的数据添 ...

  5. CCCC 正整数A+B

    题意: 本题的目标很简单,就是求两个正整数A和B的和,其中A和B都在区间[1,1000].稍微有点麻烦的是,输入并不保证是两个正整数. 输入格式: 输入在一行给出A和B,其间以空格分开.问题是A和B不 ...

  6. 冒泡排序_python

    def popdata(ls): for i in range(len(ls)): for j in range(i+1,len(ls)): if ls[i]>ls[j]: # tmp=ls[i ...

  7. Fedora、SuSE、Redhat、Ubuntu、Centos

    想学Linux,但版本太多了,如Fedora.SuSE.Redhat.Ubuntu等,不免让人眼花缭乱,那么初学者该如何选择呢?也许很多人会不屑的说,Linux不就是个操作系统么.错!Linux不是一 ...

  8. python课后练习当前目录下有一个文件名为score3.txt的文本文件, 存放着某班学生的学号和其两门专业课的成绩。

    题目: 当前目录下有一个文件名为score3.txt的文本文件, 存放着某班学生的学号和其两门专业课的成绩.分 别用函数实现以下功能: (1) 定义函数function1,计算每个学生的平均分(取 整 ...

  9. JavaScript学习总结(四)

    这一部分我们继续介绍JavaScript的常用对象. Number对象 创建Number对象 方式1: var 变量= new Number(数字) 方式2: var 变量 = 数字; 常用的方法 t ...

  10. Codeforces Round #571 (Unrated for Div. 1+Div. 2)

    A 略 B 被删了,被这个假题搞自闭了,显然没做出来. C 开始莽了个NTT,后来发现会TLE,其实是个SB前缀和,对于这题,我无**说. #include<bits/stdc++.h> ...