跳到正文

题解

题解 P3740 【[HAOI2014]贴海报】

杨铠远约 2 分钟
原文
文章信息与版本

文章信息

发布
2019年4月24日
收录
2025年12月12日
更新
2026年11月15日
篇幅
约 2 分钟
获赞
15
题目
P3740

版本

  1. v1当前

我非常喜欢暴力的数据结构,所以我用暴力A了这道题

C++
//Code by : Y-k-y
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#define ll long long
const int N=10000010;
using namespace std;
inline int read()
{
	int res=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){res=res*10+ch-'0';ch=getchar();}
	return res*f;
}
inline void wr(int x)
{
    if(x<0){putchar('-');x=-x;}
    if(x>9) wr(x/10);putchar(x%10+'0');
}
int n,m,x,y;
int a[N],t[N];//原数组、桶

int main()
{
	n=read();m=read();
	for(int i=1;i<=m;i++)
	{
		x=read();y=read();
		for(int j=x;j<=y;j++)//直接修改
		a[j]=i;
	}
	t[0]=1;//防止不贴时也加上
	int num=0;//计数
	for(int i=1;i<=n;i++)
	{
		if(!t[a[i]]){//如果没出现过这种颜色,++
			num++;
			t[a[i]]=1;
		}
	}
	wr(num);//快输
	return 0;
}

完结散花

原文
存档评论14 条抓取于