POJ 2808 trees outside the gate (Java)

Source: Internet
Author: User

Write the code first, written in Java:

Import java.util.*;
Import java.io.*;
public class Main {
public static void Main (String []args) throws exception{
Scanner input=new Scanner (system.in);
int l=0,m=0,c,b,s=0;
L=input.nextint ();
M=input.nextint ();
int a[]=new int [l+1];
for (int i=0;i<a.length;i++) {
A[i]=1;
}
while (m>0) {
B=input.nextint ();
C=input.nextint ();
for (int i=b;i<=c;i++) {
a[i]=0;
}
m--;
}
for (int i=0;i<a.length;i++) {
if (a[i]==1) {
s++;
}
}
System.out.println (s);
}
}
The idea is to first enter the route length L, define him as an array of length, that is, l=input.nextint (); int a[]=new int [l+1];

Assign each of the arrays to a number of 1. Then accept the input interval length, the corresponding interval of the beginning and end of the middle of the array element assigned to the number 0.

The last count of 1 in the array.

Note: 1. The length of the array is l+1.

        2. If the input interval is 100,200, then the corresponding array's starting and ending positions are a[100] and a[200]. Draw a axis and see how it is.

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.