HDU 1556 Color the ball "algorithm optimization"

Source: Internet
Author: User

/*
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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.