刷墙(1187)

Time limit(ms): 1000
Memory limit(kb): 10000
Submission: 2002
Accepted: 1049
Accepted
在一面很长的墙壁上,工人们用不同的油漆去刷墙,然而可能有些地方刷过以后觉得不好看,他们会重新刷一下。有些部分因为重复刷了很多次覆盖了很多层油漆,于是很好奇那些地方被刷过多少种颜色的油漆。
Description
多组数据。每组数据第一行为一整数N表示接下来N(0<=N<=200)行刷墙信息 
每行刷墙信息有两个数字B[i],E[i](0<=B[i]<=E[i]<=2000)表示这次刷的墙壁是哪一段(假设每次刷的时候油漆颜色都和之前的不同). 
接下来一行单独一个整数M(0<=M<=200)表示接下来M行询问信息 
每行两个数字begin[i],end[i](0<=begin[i]<=end[i]<=2000)表示询问的范围. 
Input
对于每个询问输出(end[i]-begin[i]+1)行,表示对应询问的begin[i],end[i]之间的每个点被多少种颜色的油漆覆盖过。
Output
1
2
3
4
5
6
7
8
3
1 20
5 10
10 20
2
4 6
10 11
Sample Input
1
2
3
4
5
6
1
2
2
3
2
Sample Output
换行用\r\n
#include<stdio.h>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int q[10000] = { 0 };
	int shua[10000] = { 0 };
	int n;
	while (cin >> n)
	{
		memset(q, 0, sizeof(q));
		memset(shua, 0, sizeof(shua));
		for (int i = 0; i < n; i++)
		{
			int a, b;
			scanf("%d %d", &a, &b);
			q[a] += 1;
			q[b+1] += -1;

		}
		int t = 0;
		for (int i = 0; i < 2001; i++)
		{
			t += q[i];
			shua[i] = t;
		}
		cin >> n;
		for (int j = 0; j < n; j++)
		{
			int s, e;
			scanf("%d %d", &s, &e);
			for (int i = s; i <= e; i++)
			{
				printf("%d\r\n", shua[i]);
			}
		}
	}
	return 0;//by swust_t_p
}

全部评论

相关推荐

许愿顺顺利利
牛客740257869号:两个百分之18 hh
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务