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. python 开发技巧(2)-- Django的安装与使用

    一.安装Django pip3 install django 或者直接使用PyCharm安装 参考 二.添加环境变量 将 "(python安装路径)\Scripts" 添加到环境变 ...

  2. pip依赖安装与记录

    pip freeze requirements.txt是一个常常被许多Flask应用用于列出它所依赖的包的文本文件.它是通过pip freeze > requirements.txt生成的. 使 ...

  3. windows下用py2exe打包脚本为可双击运行程序

    文件夹结构: ├── readme.txt ├── settings.py #程序参数 ├── settings.pyc ├── setup.py    #安装文件 ├── spider.ico   ...

  4. python socket编程入门(编写server实例)+send 与sendall的区别与使用方法

    python 编写server的步骤: 1. 第一步是创建socket对象.调用socket构造函数.如: socket = socket.socket( family, type ) family参 ...

  5. Laravel创建模型

    laravel中创建模型 <?php /** * Created by PhpStorm. * 新建模型 * User: chuang * Date: 17-1-15 * Time: 上午9:1 ...

  6. 使用神器MobaXterm连接远程mysql和redis

    https://mobaxterm.mobatek.net/download-home-edition.html mysql redis 连接测试 mysql 127.0.0.1 3307 密码使用线 ...

  7. 安装使用yarn,使用国内镜像加速npm和yarn

    安装yarn https://yarnpkg.com/lang/zh-hans/docs/install/ 使用国内镜像加速npm和yarn 1. npm config set registry=ht ...

  8. tomcat NIO配置

    1.tomcat NIO配置 今天在查看日志时发现tomcat的Socket连接方式为bio,于是我想既然有bio那肯定有nio.果然,一查就发现tomcat在6.0之后就可以配置nio的方式.nio ...

  9. Cocos2d-x Lua中实例:帧动画使用

    下面我们通过一个实例介绍一下帧动画的使用,这个实例如下图所示,点击Go按钮开始播放动画,这时候播放按钮标题变为Stop,点击Stop按钮可以停止播放动画. 帧动画实例 下面我们再看看具体的程序代码,首 ...

  10. #1560 : H国的身份证号码II(dp+矩阵快速幂)

    #1560 : H国的身份证号码II 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 H国的身份证号码是一个N位的正整数(首位不能是0).此外,由于防伪需要,一个N位正整 ...