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. 关于torch.flatten的笔记

    先看函数参数: torch.flatten(input, start_dim=0, end_dim=-1) input: 一个 tensor,即要被“推平”的 tensor. start_dim: “ ...

  2. 吴裕雄--天生自然 PHP开发学习:运算符

    <?php $x=10; $y=6; echo ($x + $y); // 输出16 echo '<br>'; // 换行 echo ($x - $y); // 输出4 echo ' ...

  3. 一个例子搞清楚Java程序执行顺序

    当我们new一个GirlFriend时,我们都做了什么? 一个例子搞懂Java程序运行顺序 public class Girl { Person person = new Person("G ...

  4. Python自学之路---Day13

    目录 Python自学之路---Day13 常用的三个方法 匹配单个字符 边界匹配 数量匹配 逻辑与分组 编译正则表达式 其他方法 Python自学之路---Day13 常用的三个方法 1.re.ma ...

  5. Tomcat启动失败原因: More than one fragment with the name [spring_web] was found. 解决

    将一个eclipse上搭建好的项目移到idea开发时遇到的问题,tomcat启动时报了3个错误 -Nov- :: ms -Nov- ::)-127.0.0.1] org.apache.tomcat.u ...

  6. Neo4j安装配置(mac)

    Neo4j安装配置(mac) 1.下载APP 注意:无需配置变量 下载地址:https://neo4j.com/download/ 2.安装程序并启动 3.创建数据库(local) 选择版本 4.启动 ...

  7. UML-GoF设计模式

    我认为,本章是重点中的重点.并非23个模式都被广泛应用,其中常用和最为有效的大概有15个模式. 1.适配器(Adapter) 1).使用场景 使用一个已经存在的类,但如果他的接口,也就是他的方法和你的 ...

  8. CSS3 box-shadow 效果大全(内阴影,外阴影,三边阴影,双边阴影,单边阴影,细线描边…)

    /* offset-x | offset-y | color */ box-shadow: 60px -16px teal; /* offset-x | offset-y | blur-radius ...

  9. 2020/1/29 PHP代码审计之XSS漏洞

    0x00 XSS漏洞简介 人们经常将跨站脚本攻击(Cross Site Scripting)缩写为CSS,但这会与层叠样式表(Cascading Style Sheets,CSS)的缩写混淆.因此,有 ...

  10. POJ 1979:Red and Black

    Red and Black Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 26058   Accepted: 14139 D ...