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 with the enormous Input/Output warning. You are expected to be able to process at least 2.5MB 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.


题解:记录这道题主要是为了记录java中Scanner和BufferReader的区别,开始用Scanner,效率非常低,所以就TLE了。根据StackOverFlow里面解释:BufferReader只是从流中读入数据,但不对数据做任何处理,Scanner按照需求解析数据并读入,比如nextInt(),nextDouble()等。更详细的答案还有这里

总结一下:

  • 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.
  • Scanner can parse the underlying stream for primitive types and strings using regular expressions.
  • A scanner however is not thread safe, it has to be externally synchronized.

对于原文中的“ A scanner can do all that a BufferedReader can do and at the same level of efficiency as well.”不太认同,因为通过OJ来看,BufferReader的效率确实比Scanner高。

BufferReader的用法就用这道题的AC代码记录:

 import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader; public class Main { public static void main(String[] args) {
// TODO Auto-generated method stub
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
try{
String[] line =(bf.readLine()).split(" ");
int n = Integer.parseInt(line[0]);
int k = Integer.parseInt(line[1]);
int count = 0;
while(n-- > 0){
int num = Integer.parseInt(bf.readLine());
if(num%k == 0)
++count;
}
System.out.println(count);
}
catch(IOException e){
System.out.print("input error");
}
} }

【CodeChef】Enormous Input Test的更多相关文章

  1. 【CodeChef】Querying on a Grid(分治,最短路)

    [CodeChef]Querying on a Grid(分治,最短路) 题面 Vjudge CodeChef 题解 考虑分治处理这个问题,每次取一个\(mid\),对于\(mid\)上的三个点构建最 ...

  2. 【CodeChef】Palindromeness(回文树)

    [CodeChef]Palindromeness(回文树) 题面 Vjudge CodeChef 中文版题面 题解 构建回文树,现在的问题就是要求出当前回文串节点的长度的一半的那个回文串所代表的节点 ...

  3. 【CodeChef】Find a special connected block - CONNECT(斯坦纳树)

    [CodeChef]Find a special connected block - CONNECT(斯坦纳树) 题面 Vjudge 题解 还是一样的套路题,把每个数字映射到\([0,K)\)的整数, ...

  4. 【CODECHEF】【phollard rho + miller_rabin】The First Cube

    All submissions for this problem are available. Read problems statements in Mandarin Chinese and Rus ...

  5. 【apache】No input file specified

    默认的 RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]规则在apache fastcgi模式下会导致No input file specified. 修改成 Re ...

  6. 【转】html input radio取得被选中项的value

    html代码: <input id="rad" name="rad" type="radio" value="1" ...

  7. 【转】Angular Input格式化

    今天在Angular中文群有位同学问到:如何实现对input box的格式化.如下的方式对吗? <input type="text" ng-model="demo. ...

  8. 【转】unity3d input输入

    Input 输入 按键 Input.GetKey(“up”) = Input.GetKey(KeyCode.UpArrow) 按住键盘上键 Input.GetKeyDown (“up”) 按下键盘上键 ...

  9. 【codechef】FN/Fibonacci Number

    题意 给出 c 和 P ,求最小的非负整数 n 使得 \(Fib(n)=c(mod~ P)\) 其中 P 是质数且 模 10 等于一个完全平方数(也就是说 P 的末位是个完全平方数,那么只能是 1 或 ...

随机推荐

  1. AtCoder Regular Contest 070 D - No Need 想法:利用单调性二分+bitset优化

    /** 题目:D - No Need 链接:http://arc070.contest.atcoder.jp/tasks/arc070_b 题意:给出N个数,从中选出一个子集,若子集和大于等于K,则这 ...

  2. 浅谈web前端安全

    单纯地在你的客户端弹出信息只是类似于迫使你在自己的房间脱衣服--没人看得到,自然也不算啥恶意行为.那么如果我把你的信息通过脚本发送到我的服务器保存起来呢?先放心,我不打算这么做,也没那笔闲钱去购置一个 ...

  3. Linux gcc编译器

    GNU CC(通常称为GCC)是GNU项目的编译器,他能够编译C.C++语言编写的程序. 使用gcc,程序员可以对编译过程有更多控制,编译过程分为3个阶段. --预处理 --汇编 --链接 程序员可以 ...

  4. MongoDB API和python操作

    安装 下载mongodb的版本,两点注意 根据业界规则,偶数为稳定版,如1.6.X,奇数为开发版,如1.7.X 32bit的mongodb最大只能存放2G的数据,64bit就没有限制 到官网,选择合适 ...

  5. 在NodeJS中使用流程控制工具Async

    本文介绍一款流程控制工具async,在编写接口或者编写测试用例的过程中总是会用到它. 由于nodejs是异步编程模型,有一些在同步编程中很容易做到的事情,现在却变得很麻烦.Async的流程控制就是为了 ...

  6. C# 持续序列化对象追加到文件的方法

    最近有个需求,将内存和帧数数据序列化到二进制文件.为了节省内存,采用了100个对象的数组,每次存满就序列化到文件,然后归零继续存,以追加的性式继续序列化到原有文件. 这样相当于多个数组对象存在了同一个 ...

  7. Exponentiation(高精度大数)

    Exponentiation Description Problems involving the computation of exact values of very large magnitud ...

  8. JS复制粘贴解决方案

    var clipboardData = window.clipboardData; //for IE if (!clipboardData) { // for chrome window.prompt ...

  9. 分布式缓存的一致性Hash算法 2 32

    w 李智慧

  10. CSS3选择器:nth-child与:nth-of-type区别

    一.:nth-child 1.1 说明 :nth-child(n)选择器匹配属于其父元素的第N个子元素,不论元素的类型.n可以是数字.关键词或公式. 注意:如果第N个子元素与选择的元素类型不同则样式无 ...