/*
Solution thinking: Solve the first number at a time, let the first number plus one, the last number minus one after the number. We can think of the last addition, the number of occurrences of the previous number and the number of occurrences of themselves.
The person who solve the problem: Lingnichong
Problem-solving time: 2014-10-25-10:30:46
Problem-solving experience: Because the test interval is very large, so the problem is easy to time out
*/
Color the ballTime limit:9000/3000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total Submission (s): 9738 Accepted Submission (s): 5013
Problem descriptionn a row of balloons, numbered from left to right to 1,2,3....N. Each time a given 2 integers a B (a <= B), Lele will be riding his "little Pigeon" brand electric car from balloon a start to balloon B to each balloon painted once color. But n times after Lele has forgotten the first balloon has been painted several times, can you help him to figure out how many times each balloon has been painted color?
Input each test instance first behaves as an integer N, (n <= 100000). The next N rows, each line consists of 2 integers a B (1 <= a <= b <= N).
When n = 0, the input ends.
Output one row for each test instance, including n integers, and the number of numbers representing the number of times the balloon was painted in total.
Sample Input
31 12 23 331 11 21 30
Sample Output
1 1 13) 2 1
Author8600
#include <stdio.h> #include <string.h> #define MAXN 100000+10int arr[maxn];int main () {int n,i,j;int a,b,t,m; while (scanf ("%d", &n), N) {M=0;memset (arr,0,sizeof (arr)); for (i=0;i<n;i++) { scanf ("%d%d", &a,&b) ; arr[a]++,arr[b+1]--;} for (i=1;i<n;i++) {m+=arr[i];p rintf ("%d", m);} printf ("%d\n", M+arr[n]);} return 0;}
HDU 1556 Color the ball "algorithm optimization"