【CodeChef】Enormous Input Test
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的更多相关文章
- 【CodeChef】Querying on a Grid(分治,最短路)
[CodeChef]Querying on a Grid(分治,最短路) 题面 Vjudge CodeChef 题解 考虑分治处理这个问题,每次取一个\(mid\),对于\(mid\)上的三个点构建最 ...
- 【CodeChef】Palindromeness(回文树)
[CodeChef]Palindromeness(回文树) 题面 Vjudge CodeChef 中文版题面 题解 构建回文树,现在的问题就是要求出当前回文串节点的长度的一半的那个回文串所代表的节点 ...
- 【CodeChef】Find a special connected block - CONNECT(斯坦纳树)
[CodeChef]Find a special connected block - CONNECT(斯坦纳树) 题面 Vjudge 题解 还是一样的套路题,把每个数字映射到\([0,K)\)的整数, ...
- 【CODECHEF】【phollard rho + miller_rabin】The First Cube
All submissions for this problem are available. Read problems statements in Mandarin Chinese and Rus ...
- 【apache】No input file specified
默认的 RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]规则在apache fastcgi模式下会导致No input file specified. 修改成 Re ...
- 【转】html input radio取得被选中项的value
html代码: <input id="rad" name="rad" type="radio" value="1" ...
- 【转】Angular Input格式化
今天在Angular中文群有位同学问到:如何实现对input box的格式化.如下的方式对吗? <input type="text" ng-model="demo. ...
- 【转】unity3d input输入
Input 输入 按键 Input.GetKey(“up”) = Input.GetKey(KeyCode.UpArrow) 按住键盘上键 Input.GetKeyDown (“up”) 按下键盘上键 ...
- 【codechef】FN/Fibonacci Number
题意 给出 c 和 P ,求最小的非负整数 n 使得 \(Fib(n)=c(mod~ P)\) 其中 P 是质数且 模 10 等于一个完全平方数(也就是说 P 的末位是个完全平方数,那么只能是 1 或 ...
随机推荐
- Oracle 数据库排错之 ORA-00600
[错误代码] ORA-00600 [问题描述] ORA-00600: [kcratr1_lastbwr]错误的处理办法 [问题分析] 出现该错误是因为系统强制关机造成的!症状为数据库无法打开! [问题 ...
- Linux 比较重要且难掌握命令 集合
1. find find path –option [-print] [-exec command] {} \; find . -maxdepth 1 -name aa find . -maxdept ...
- POJ 1426 Find The Multiple && 51nod 1109 01组成的N的倍数 (BFS + 同余模定理)
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21436 Accepted: 877 ...
- ios 2017启动页(Launch Screen Images)、图标(App Icon)尺寸大小
ios 2017启动页(Launch Screen Images).图标(App Icon)尺寸大小 iPhone Portrait iOS 8,9-Retina HD 5.5 (1242×220 ...
- try finally 执行顺序
class Exc{ int a; int b; } public class Except { @SuppressWarnings("finally") static int c ...
- gridgroup行内编辑删除
Ext.define('Task', { extend: 'Ext.data.Model', idProperty: 'taskId', fields: [ { name: 'projectId', ...
- Python 邮箱
#coding:utf-8from email.header import Headerfrom email.mime.text import MIMETextfrom email.utils imp ...
- hdu 4262(线段树)
题目:有一个圈,可以从某个位置取球,给出原有的顺序,有三种操作,左旋一次,右旋一次,取球,要求按顺序取球,问需要操作多少次 显然操作是确定的,每次将目标球旋转过来,找出左旋和右旋操作少的,然后取球. ...
- PowerDesigner之设置(2)——扩展属性
数据库:SQL2000 PD版本:16 在PowerDesigner之设置(1)中,创建表的表头注释部分由于中文的原因无法定长,这里我们用PD的扩展方法来解决. 具体方法如下: 主菜单DataBase ...
- 时间格式转换 json 转 datetime js c#
情景描述:使用C#在后台中传递时间到ajax中,因为是一个list<model>就直接用了Json 作为载体,但是在js中获得到的时间是var time='/Date(********** ...