HDU1556 线扫
昨天睡得太晚,今天又在看新算法,明天事情也多,烦,所以今天刷刷水题就过去了。
叫我用线段树,我反而搞不来
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
int a[100010],sum[100010];
int main()
{
int n,i,j,m,k,x,y;
while(~scanf("%d",&n)&&n){
memset(a,0,sizeof(a));
for(i=1;i<=n;i++) {
scanf("%d%d",&x,&y);
a[x]++;
a[y+1]--;
}
for(i=1;i<=n;i++)
sum[i]=sum[i-1]+a[i];
printf("%d",sum[1]);
for(i=2;i<=n;i++)
printf(" %d",sum[i]);
printf("\n");
}
return 0;
}
It is your time to fight!