Aizu2969 Universal and Existential Quantifiers

Posted gk0328

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Aizu2969 Universal and Existential Quantifiers相关的知识,希望对你有一定的参考价值。

http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2969

题意:

(Question1:)

求覆盖一段区间所需的最少区间数量。

(Question2:)

求最少的区间数,使任意取区间都能覆盖整段区间

贪心/差分

吐槽:把两道题合到一道题里,没水平

首先离散化

(Question1:)

普通贪心,将区间按左端点排序,在满足左端点条件下贪心取右端点最大值

(Question2:)

差分,寻找被区间覆盖最少的那个点,根据容斥原理,必须用区间总数减去覆盖那个点的区间数量再加(1)

(C++ Code:)

#include<cstdio>
#include<iostream>
#include<algorithm>
#define ll long long
#define N 400005
using namespace std;
struct node
{
	int x,y;
	bool operator < (const node b) const
	{
		return (x<b.x)||(x==b.x&&y<b.y);
	}
}a[N];
ll c[N],d[N][2];
int n,cnt,t,last,ans,ans2,q[N];
ll l;
int main()
{
	scanf("%d%lld",&n,&l);
	for (int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&c[i*2-1],&c[i*2]);
		d[i][0]=c[i*2-1],d[i][1]=c[i*2];
	}
	sort(c+1,c+n+n+1);
	cnt=unique(c+1,c+n+n+1)-c-1;
	for (int i=1;i<=n;i++)
	{
		a[i].x=lower_bound(c+1,c+cnt+1,d[i][0])-c;
		a[i].y=lower_bound(c+1,c+cnt+1,d[i][1])-c;
	}
	l=lower_bound(c+1,c+cnt+1,l)-c;
	sort(a+1,a+n+1);
	int s,t=1;
	int g=1;
	while (t<l)
	{
		s=t;
		while (a[g].x<=s&&g<=n)
		{
			t=max(t,a[g].y);
			g++;
		}
		ans++;
	}
	for (int i=1;i<=n;i++)
	{
		q[a[i].x]++;
		q[a[i].y]--;
	}
	ans2=n;
	s=0;
	for (int i=1;i<l;i++)
	{
		s+=q[i];
		ans2=min(s,ans2);
	}
	printf("%d %d
",ans,n-ans2+1);
}

以上是关于Aizu2969 Universal and Existential Quantifiers的主要内容,如果未能解决你的问题,请参考以下文章

Reference Collapsing Rules, Universal Reference and the implementation of std::forward() and std::mo

Marlin:Preprocessing zkSNARKs with Universal and Updatable SRS学习笔记

Sample Preparation by Easy Extraction and Digestion (SPEED) - A Universal, Rapid, and Detergent-free

论文阅读 | Universal Adversarial Triggers for Attacking and Analyzing NLP

[Javascript] Ex: concatAll, map and filter

Aizu 2249 & cf 449B