Codility--- NumberOfDiscIntersections
Task description
We draw N discs on a plane. The discs are numbered from 0 to N − 1. A zero-indexed array A of N non-negative integers, specifying the radiuses of the discs, is given. The J-th disc is drawn with its center at (J, 0) and radius A[J]. We say that the J-th disc and K-th disc intersect if J ≠ K and the J-th and K-th discs have at least one common point (assuming that the discs contain their borders). The figure below shows discs drawn for N = 6 and A as follows: A[0] = 1 A[1] = 5 A[2] = 2 A[3] = 1 A[4] = 4 A[5] = 0 There are eleven (unordered) pairs of discs that intersect, namely:
Write a function:
that, given an array A describing N discs as explained above, returns the number of (unordered) pairs of intersecting discs. The function should return −1 if the number of intersecting pairs exceeds 10,000,000. Given array A shown above, the function should return 11, as explained above. Assume that:
Complexity:
Elements of input arrays can be modified. Solution
Programming language used: Java
Total time used: 4 minutes
Code: 15:38:12 UTC, java, final, score: 100
|
https://codility.com/demo/results/training5N9W8K-3M3/
最新文章
- Thrift-java实例
- 备忘: Install MODI for use with Microsoft Office 201x
- K2BPM怎么让金融数据更有意义?
- yousa_team团队项目——兼职平台网站 工作进度
- jmeter 构建一个LDAP测试计划
- [C语言 - 1.2] 类型说明符、字符、数组
- 实现View弹性滑动例子
- c++11的for新用法 (重新练习一下for_each)
- unique &;unique_copy
- Ubuntu下将vim配置为Python IDE(转)
- Cocos2d-x实现简单的翻牌效果
- MVC客户管理(添加、修改、查询、分页)
- [Codeforces Round #438][Codeforces 868D. Huge Strings]
- CentOS7的内核优化
- Qt 出现“undefined reference to `vtable for”
- BZOJ4964 : 加长的咒语
- Linux集锦
- 【SQL】如何使用SQL like 方法和SQL [charlist] 通配符(SQL like的拓展)
- Win7 无法访问Installer服务
- Ubuntu 下安装 Swoole