zoukankan      html  css  js  c++  java
  • [HAOI2011]problem a

    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


    直接求最少不好求,我们考虑求出最多有多少个人说了真话,直接用n减去即可

    (f[i])表示在前i名最多有多少人说了真话,转移即为(f[i]=max{f[j-1]+sum[j][i]})

    其中,(sum[j][i])表示名次区间在([j,i])中的人数

    直接记二维显然不行,有效的区间其实很少,因此我们可以用pair去映射一个int

    /*program from Wolfycz*/
    #include<map>
    #include<cmath>
    #include<cstdio>
    #include<vector>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #define inf 0x7f7f7f7f
    using namespace std;
    typedef long long ll;
    typedef unsigned int ui;
    typedef unsigned long long ull;
    inline char gc(){
    	static char buf[1000000],*p1=buf,*p2=buf;
    	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
    }
    inline int frd(){
    	int x=0,f=1; char ch=gc();
    	for (;ch<'0'||ch>'9';ch=gc())	if (ch=='-')	f=-1;
    	for (;ch>='0'&&ch<='9';ch=gc())	x=(x<<3)+(x<<1)+ch-'0';
    	return x*f;
    }
    inline int read(){
    	int x=0,f=1; char ch=getchar();
    	for (;ch<'0'||ch>'9';ch=getchar())	if (ch=='-')	f=-1;
    	for (;ch>='0'&&ch<='9';ch=getchar())	x=(x<<3)+(x<<1)+ch-'0';
    	return x*f;
    }
    inline void print(int x){
    	if (x<0)	putchar('-'),x=-x;
    	if (x>9)	print(x/10);
    	putchar(x%10+'0');
    }
    const int N=1e5;
    map<pair<int,int>,int>mp;
    vector<int>vec[N+10];
    int f[N+10];
    int main(){
    	int n=read();
    	for (int i=1;i<=n;i++){
    		int l=read()+1,r=n-read();
    		if (l>r)	continue;
    		map<pair<int,int>,int>::iterator it=mp.find(make_pair(l,r));
    		if (it==mp.end()){
    			mp.insert(map<pair<int,int>,int>::value_type(make_pair(l,r),1));
    			vec[r].push_back(l);
    		}else	(it->second)++;
    	}
    	for (int i=1;i<=n;i++){
    		f[i]=f[i-1];
    		for (vector<int>::iterator it=vec[i].begin();it!=vec[i].end();it++)
    			f[i]=max(f[i],f[(*it)-1]+min(i-(*it)+1,mp.find(make_pair((*it),i))->second));
    	}
    	printf("%d
    ",n-f[n]);
    	return 0;
    }
    
  • 相关阅读:
    jdk1.8新特性
    linux centos虚拟机安装
    linux基本命令介绍
    JavaScript与Java的区别
    jQuery UI的基本使用方法与技巧
    jQuery Ajax 实例 ($.ajax、$.post、$.get)
    .NET批量大数据插入性能分析及比较
    .NET中的CSV导入导出(实例)
    jquery中push()的用法(数组添加元素)
    .net如何后台批量删除
  • 原文地址:https://www.cnblogs.com/Wolfycz/p/10002516.html
Copyright © 2011-2022 走看看