hdu 1556

这题一看就想用线段树或数状数组做,过了以后再上网搜别人的解法,发现有人居然没用线段树或数状数组,利用类似部分和的思想,太强大了!

/*
* hdu1556/win.cpp
* Created on: 2011-11-13
* Author : ben
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <numeric>
#include <cctype>
using namespace std;

const int MAXN = 100010;
int tuse[MAXN];
int main() {
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif
int N, a, b, ans;
while (scanf("%d", &N) == 1 && N > 0) {
memset(tuse, 0, sizeof(tuse));
for (int i = 0; i < N; i++) {
scanf("%d%d", &a, &b);
tuse[a]++;
tuse[b + 1]--;
}
ans = tuse[1];
printf("%d", ans);
for (int i = 2; i <= N; i++) {
printf(" %d", ans += tuse[i]);
}
putchar('\n');
}
return 0;
}



你可能感兴趣的:(HDU)