bzoj4985 评分(二分答案+dp)
来源:互联网 发布:webuploader 跨域 php 编辑:程序博客网 时间:2024/05/19 13:45
这题是二分答案哟,想不到吧hh
每次判断x是否可行,把原数列转化成01序列。我们的目标是使得最后剩下的为1,则x可行。怎么判断呢?我们利用dp,dp[i]表示让i位置是1最少需要多少个额外的1(也就是说已经固定了的1不算)。对于前n个位置,因为情况是给定的,所以可以直接给初值。(原来是1,需要0个,原来是0,需要inf个,原来是未知,需要1个)对于以后的i,选取对应三个位置中的任意两个相加取最小值即可。(只要三个中有2个是1,则i位置就可以是1)。我们用队列模拟这个dp过程即可。
#include <bits/stdc++.h>using namespace std;#define ll long long#define inf 0x3f3f3f3f#define N 100010inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();} while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(); return x*f;}int n,m,a[N],b[N];bool jud(int x){ queue<int>q;int res=0; for(int i=1;i<=n-m;++i) if(b[i]>=x) res++; for(int i=1;i<=n;++i){ if(!a[i]) q.push(1); else if(a[i]>=x) q.push(0); else q.push(inf); } while(q.size()>1){ int x1=q.front();q.pop(); int x2=q.front();q.pop(); int x3=q.front();q.pop(); q.push(min(min(x1+x2,x1+x3),min(x2+x3,inf))); } if(q.front()<=res) return 1; else return 0;}int main(){// freopen("a.in","r",stdin); n=read();m=read(); for(int i=1;i<=m;++i){ int x=read(),y=read();a[y]=x; } for(int i=1;i<=n-m;++i) b[i]=read(); int l=1,r=1e9,ans=0; while(l<=r){ int mid=l+r>>1; if(jud(mid)) ans=mid,l=mid+1;else r=mid-1; } printf("%d\n",ans); return 0;}
阅读全文
0 0
- bzoj4985 评分(二分答案+dp)
- BZOJ 4985: 评分 二分答案 dp判定
- hdu3586(树形DP+二分答案)
- Topcoder SRM658,DP+二分答案,
- 二分答案加DP判断
- [dp][二分答案]最大正方形
- UVALive 4625 Garlands(二分答案 + DP)
- UVALive 3608 Period(二分答案+DP)
- [BZOJ1044]HAOI2008木棍分割|DP|二分答案
- so就 (二分答案 dp 贪心)
- 【HDU3586】Information Disturbing-二分答案+树形DP
- CEOI2017 D1T3 mousetrap 树形dp+二分答案
- 道路覆盖 (二分答案+状压DP)
- hdu 3681 二分枚举答案+dp判断答案
- hdoj 3586 Information Disturbing(二分答案+树dp判断)
- HDU 3681 Prison Break (二分答案+状压DP+bfs预处理)
- SPOJ1748 - SEQPAR2 二分答案 DP优化 单调队列+线段树
- POJ 3208 Apocalypse Someday 二分答案+数位DP
- 简单组合java.util.Map<K,V>实现Map<K,P,V>
- 百度地图api版本不同,几处不同
- 把数组排成最小的数
- 字符是如何被存储的
- CSDN
- bzoj4985 评分(二分答案+dp)
- Your branch is ahead of 'origin/master' by 1 commit
- 4010: [HNOI2015]菜肴制作
- 业务层刻意抛出异常,全局异常的捕获它并按格式返回
- IntelliJ IDEA导入多个eclipse项目到同一个workspace下
- go web :5 用Interface{}简化对json的处理
- spring注解的使用
- pandas.read_csv参数整理
- Intellij IDEA 中文输入框不跟随怎么办?