[Codechef] enormous input test

Source: Internet
Author: User

The purpose of this problem is to verify whether the method you are using to read input data is sufficiently fast to handle problems branded withEnormous input/outputWarning. You are expected to be able to process at least 2.5 MB of input data per second at runtime.

Input

The input begins with two positive integers n k (n, k <= 107). The next n lines of input contain one positive integer Ti, not greater than 109, each.

Output

Write a single integer to output, denoting how many integers Ti are divisible by K.

Question: record this question mainly to record the difference between the observer and bufferreader in Java. It starts to use the observer, and the efficiency is very low, so it's just TLE. According to stackoverflow, bufferreader only reads data from the stream, but does not process the data. The Handler parses and reads the data as needed, such as nextint () and nextdouble. Here is the more detailed answer.

Summary:

  • A bufferedreader is a simple class meant to efficiently read from the underling stream.
  • Bufferedreader is synchronized, so read operations on a bufferedreader can safely be done from multiple threads.
  • Parameter can parse the underlying stream for primitive types and strings using regular expressions.
  • A specified however is not thread safe, it has to be externally synchronized.

For the original article "A could can do all that a bufferedreader can do and at the same level of efficiency as well. I don't quite agree, because from the perspective of OJ, bufferreader is indeed more efficient than bytes.

The usage of bufferreader is recorded using the AC code of this question:

 1 import java.io.BufferedReader; 2 import java.io.IOException; 3 import java.io.InputStreamReader; 4  5 public class Main { 6  7     public static void main(String[] args) { 8         // TODO Auto-generated method stub 9         BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));10         try{11             String[] line =(bf.readLine()).split(" ");12             int n = Integer.parseInt(line[0]);13             int k = Integer.parseInt(line[1]);14             int count = 0;15             while(n-- > 0){16                 int num = Integer.parseInt(bf.readLine());17                 if(num%k == 0)18                     ++count;19             }20             System.out.println(count);21         }22         catch(IOException e){23             System.out.print("input error");24         }25     }26 27 }

 

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.