【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 或 ...
随机推荐
- zeppelin部署
1.下载解压2.修改conf/zeppelin-env.sh,添加如下两行 export ZEPPELIN_PORT= export MASTER=spark://master:7077 3.启动 b ...
- Data Replication in a Multi-Cloud Environment using Hadoop & Peer-to-Peer technologies
http://fbevmware.blogspot.com/2013/12/data-replication-in-multi-cloud.html 要FQ... —————————————————— ...
- 挂载samb目录
不管是ubuntu还是fedora文件管理器都带有挂载浏览smb目录的工具,但是我却找不到它的挂载点,所以想用命令行拷贝东西就没办法了,还是需要使用传统的挂载方式, mount -t cifs -o ...
- Linux shell (ssh批量配置免秘)读取配置文件,进行远程操作
需要目标机器安装有 expect 命令 分成五个文件config.ini(配置文件).id_ras.pub(公钥).read.sh(一个函数,用于读取配置文件).test.sh(执行文件).run.s ...
- 怎么在Word中找MathType菜单
一些用户朋友在使用word的过程中,发现自己突然找不到MathType公式编辑器菜单项了,而这个时候又急着编写公式,所以会特别的着急.下面我们就来针对这个问题好好的给大家分析一下,并提供解决方案.请关 ...
- c++通过类名动态创建对象
转载:http://www.seacha.com/article.php/knowledge/cbase/2013/0615/2154.html 主要思想:在每次创建类的过程中,通过各自类的辅助类(所 ...
- ASSERT(m_hWnd == hWndOrig) - 解决之
该问题产生的原因为:创建类型为regular dll 的MFC dll中的窗口创建与其它DLL或EXE中的窗口创建混乱. 比如:dll1 中函数 fun1() 调用 dll2 中函数 fun2(),在 ...
- vs报错找不到错在哪里!Validation failed for one or more entities
今天在处理Entity Framework修改数据库时,报错: Validation failed for one or more entities. See 'EntityValidationErr ...
- Java工程师面试题整理[社招篇]
http://blog.csdn.net/jackfrued/article/details/44921941 1.面向对象的特征有哪些方面?2.访问修饰符public,private,protect ...
- JavaWeb 之事务
什么是事务? 事务就是逻辑上的一组操作,组成事务的各个执行单元,操作要么全部成功,要么全部失败. 以转账为例: 张三给李四转账,张三扣1000,李四加1000; 加钱和扣钱两个操作组成了一个事务. 1 ...