2298: [HAOI2011]problem a

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://www.lydsy.com/JudgeOnline/problem.php?id=2298

Description

一次考试共有n个人参加,第i个人说:“有ai个人分数比我高,bi个人分数比我低。”问最少有几个人没有说真话(可能有相同的分数)

Input

第一行一个整数n,接下来n行每行两个整数,第i+1行的两个整数分别代表ai、bi

Output

一个整数,表示最少有几个人说谎

Sample Input

3

2 0

0 2

2 2

Sample Output

1

HINT

100%的数据满足: 1≤n≤100000   0≤ai、bi≤n

题意

题解:

转换一下,就是求最多有多少个人满足题意

dp[i]表示前i名最多有多少个人没有说谎

那么dp[i]=max(dp[i],dp[j]+sum[j+1][i])其中sum(j+1](i)表示赞同这个区间的人数

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200500
#define mod 1001
#define eps 1e-9
#define pi 3.1415926
int Num;
//const int inf=0x7fffffff;
const ll inf=;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************* struct node
{
int l,r;
};
vector<int> Q[maxn];
map<pair<int,int> ,int> H;
int dp[maxn];
int main()
{
int n=read();
for(int i=;i<n;i++)
{
int x=read(),y=read();
if(x+y>=n)continue;
x++,y=n-y;
if(!H[make_pair(x,y)])Q[y].push_back(x);
H[make_pair(x,y)]++;
if(H[make_pair(x,y)]>y-x+)H[make_pair(x,y)]=y-x+;
}
for(int i=;i<=n;i++)
{
dp[i]=dp[i-];
for(int j=;j<Q[i].size();j++)
dp[i]=max(dp[i],dp[Q[i][j]-]+H[make_pair(Q[i][j],i)]);
}
printf("%d\n",n-dp[n]);
}

BZOJ 2298: [HAOI2011]problem a 动态规划的更多相关文章

  1. BZOJ 2298: [HAOI2011]problem a【动态规划】

    Description 一次考试共有n个人参加,第i个人说:“有ai个人分数比我高,bi个人分数比我低.”问最少有几个人没有说真话(可能有相同的分数) Input 第一行一个整数n,接下来n行每行两个 ...

  2. bzoj 2298: [HAOI2011]problem a

    Description 一次考试共有n个人参加,第i个人说:"有ai个人分数比我高,bi个人分数比我低."问最少有几个人没有说真话(可能有相同的分数) Input 第一行一个整数n ...

  3. 【BZOJ 2298】 2298: [HAOI2011]problem a (DP)

    2298: [HAOI2011]problem a Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 1326  Solved: 637 Descript ...

  4. Bzoj 2301: [HAOI2011]Problem b(莫比乌斯反演+除法分块)

    2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MB Description 对于给出的n个询问,每次求有多少个数对(x, ...

  5. bzoj 2301: [HAOI2011]Problem b

    2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MB Submit: 3757 Solved: 1671 [Submit] ...

  6. BZOJ 2301: [HAOI2011]Problem b 莫比乌斯反演

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 1007  Solved: 415[Submit][ ...

  7. BZOJ 2302: [HAOI2011]Problem c( dp )

    dp(i, j)表示从i~N中为j个人选定的方案数, 状态转移就考虑选多少人为i编号, 然后从i+1的方案数算过来就可以了. 时间复杂度O(TN^2) ------------------------ ...

  8. BZOJ 2301: [HAOI2011]Problem b( 数论 )

    和POI某道题是一样的...  http://www.cnblogs.com/JSZX11556/p/4686674.html 只需要二维差分一下就行了. 时间复杂度O(MAXN + N^1.5) - ...

  9. BZOJ 2301 [HAOI2011]Problem b (分块 + 莫比乌斯反演)

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 6519  Solved: 3026[Submit] ...

随机推荐

  1. C#编程让Outlook乖乖交出帐户密码

    许多人习惯于让Outlook记住密码,收邮件时便不必每次都输入邮箱密码,一切让Outlook代劳.但时间一长,马虎的人会把自己的邮箱密码忘记,这样就无法重新设置或者登录Web界面收取邮件了.Outlo ...

  2. PHPUNIT 单元测试

    在windows上的安装可以参考其手册 首先下载phpunit.phar文件 1. 为php的二进制可执行文件建立 一个目录,如C:\bin 2. 将C:\bin添加到系统环境变量中, 3. 打开命令 ...

  3. java的四舍五入算法

    粗力度的四舍五入为整数 package math; public class MathRoundTest { /** * Math类中提供了三个与取整有关的方法:ceil,floor,round, * ...

  4. 优秀it博客和文章

    优秀博客 综合 杨文博(供职于百度公司,任复合搜索部资深研发工程师,目前作为tech lead,负责垂直行业搜索后端架构研发.) 杨远骋 徐宥(Google 软件工程师. 这个中文博客是我的思考记录, ...

  5. JS实现网页下载[转]

    function downloadById() {        var url = "http://localhost:64610/WorkProcess/ResumeDetail/7&q ...

  6. linux 安装mongodb

    Linux 安装mongodb 1.下载mongodb linux wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon- ...

  7. js基础第四天

    多个tab栏切换class封装 <style>         *{margin:0;padding:0;}         ul{list-style:none;}         .b ...

  8. Tomcat 7 Connector 精读(1)

    这个类图是本人截取的最重要的类的方法和属性. 其中ProtocalHandler是协议处理器,tomcat支持的协议以下方法可以看到.不同协议实现了不同的ProtocalHandler类. publi ...

  9. 输入一个整数n,求从1到n这n个整数的十进制表示中1出现的次数

    题目:输入一个整数n,求从1到n这n个整数的十进制表示中1出现的次数.例如输入12,从1到12这些整数中包含1 的数字有1,10,11和12,1一共出现了5次. 分析:首先最先想到的是遍历从1到n的每 ...

  10. python 网络编程(四)---UDP服务端客户端

    1.服务器端 UDP服务器建立与TCP相类似,具体比较如下: 补充下,第四步:不必使用listen还有accept函数. 具体代码如下:(设置socket选项省略) import socket fro ...