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/
Codility--- NumberOfDiscIntersections的更多相关文章
- *[codility]Number-of-disc-intersections
http://codility.com/demo/take-sample-test/beta2010/ 这题以前做的时候是先排序再二分,现在觉得没有必要.首先圆可以看成线段,把线段的进入作为一个事件, ...
- Solution of NumberOfDiscIntersections by Codility
question:https://codility.com/programmers/lessons/4 this question is seem like line intersections qu ...
- Codility NumberSolitaire Solution
1.题目: A game for one player is played on a board consisting of N consecutive squares, numbered from ...
- codility flags solution
How to solve this HARD issue 1. Problem: A non-empty zero-indexed array A consisting of N integers i ...
- GenomicRangeQuery /codility/ preFix sums
首先上题目: A DNA sequence can be represented as a string consisting of the letters A, C, G and T, which ...
- *[codility]Peaks
https://codility.com/demo/take-sample-test/peaks http://blog.csdn.net/caopengcs/article/details/1749 ...
- *[codility]Country network
https://codility.com/programmers/challenges/fluorum2014 http://www.51nod.com/onlineJudge/questionCod ...
- *[codility]AscendingPaths
https://codility.com/programmers/challenges/magnesium2014 图形上的DP,先按照路径长度排序,然后依次遍历,状态是使用到当前路径为止的情况:每个 ...
- *[codility]MaxDoubleSliceSum
https://codility.com/demo/take-sample-test/max_double_slice_sum 两个最大子段和相拼接,从前和从后都扫一遍.注意其中一段可以为0.还有最后 ...
- *[codility]Fish
https://codility.com/demo/take-sample-test/fish 一开始习惯性使用单调栈,后来发现一个普通栈就可以了. #include <stack> us ...
随机推荐
- 【44.19%】【codeforces 727C】Guess the Array
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【37.00%】【vijos p1425】子串清除
P1425子串清除Accepted 标签:[显示标签] 描述 我们定义字符串A是字符串B的子串当且仅当我们能在B串中找到A串.现在给你一个字符串A,和另外一个字符串B,要你每次从B串中从左至右找第一个 ...
- 【64.22%】【codefoces round 382A】Ostap and Grasshopper
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 保护SSD,设置Chrome浏览器临时文件夹到ramdisk分区
很多用低端/山寨SSD的朋友都用Ramdisk来保护硬盘,一般都把系统temp目录和IE浏览器临时文件夹目录设到Ramdisk分区了. 最近用谷歌的chrome浏览器,发现浏览网页时候硬盘灯 ...
- 一个2013届毕业生(踏上IT行业)的迷茫(4)
等了大概三个月,终于到9月份了,以前没有出过远门,这次要去西安上学,一个人父母还是不放心,带了几件衣服就和父亲匆匆去坐火车,这一路有多少个第一次啊,第一次和父亲一块坐车.第一次坐火车.第一次出县城.第 ...
- 发布与订阅SQLServer
SQLServer 中发布与订阅 在对数据库做迁移的时候,会有很多方法,用存储过程,job,也可以用开源工具lettle,那么今天这些天变接触到了一种新的方法,就是SqlServer中自带的发布与订阅 ...
- ListView与GridView优化
前言 ListView是Android中最常用的控件,通过适配器来进行数据适配然后显示出来,而其性能是个很值得研究的话题.本文与你一起探讨Google I/O提供的优化Adapter方案,欢迎大家交流 ...
- 一组西门子S7 报文
03 00 00 16 11 E0 00 00 00 01 00 C1 02 10 00 C2 02 03 01 C0 01 0A(第一次握手报文) 03 00 00 16 11 D0 00 01 0 ...
- Android开发之 shape的使用
android shape的使用 shape用于设定形状,能够在selector,layout等里面使用,有6个子标签,各属性例如以下: <?xml version="1.0" ...
- java学习笔记(8)——多线程
进程:是一个程序在其自身的地址空间的一次执行活动. 线程:(区别于进程)线程没有独立的存储空间. 几个概念:时间片 线程 进程 能不能够用多进程代替多线程呢? 两个进程切换时要交换内存空间,而多 ...