[HAOI2011]problem a DP

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


Sample Input
3
2 0
0 2
2 2


Sample Output
1


这题的话,推一下限制的条件即可,大概有三个。
然后树状数组+DP即可


#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long LL;
int _min(int x, int y) {return x < y ? x : y;}
int _max(int x, int y) {return x > y ? x : y;}
int read() {
	int s = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
	return s * f;
}

struct node {int x, y;} a[110000];
int n, s[110000];
int f[110000], num[110000]; bool v[110000];
bool cmp(node a, node b) {return a.x == b.x ? a.y < b.y : a.x < b.x;}

int lowbit(int x) {return x & -x;}
void change(int x, int c) {for(int i = x; i <= n; i += lowbit(i)) s[i] = _max(s[i], c);}
int getmax(int x) {int maxx = 0; for(int i = x; i; i -= lowbit(i)) maxx = _max(maxx, s[i]); return maxx;}

int main() {
	n = read();
	int tp = 0;
	for(int i = 1; i <= n; i++) {
		int x = read(), y = read();
		if(x + y < n) {
			a[++tp].x = x + 1, a[tp].y = n - y;
		}
	} sort(a + 1, a + tp + 1, cmp);
	int maxx = 0, p = 1;
	for(int i = 1; i <= tp; i++) {
		f[i] = getmax(a[i].x - 1) + 1;
		if(a[i].x == a[i - 1].x && a[i].y == a[i - 1].y) {
			p++;
			if(a[i].y - a[i].x + 1 >= p) f[i] = f[i - 1] + 1;
		} else p = 1;
		change(a[i].y, f[i]);
		maxx = _max(maxx, f[i]);
	} printf("%d\n", n - maxx);
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值