441_ Arranging_Coins
来源:互联网 发布:日本公安知乎 编辑:程序博客网 时间:2024/06/07 03:16
/*441. Arranging CoinsYou have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins.Given n, find the total number of full staircase rows that can be formed.n is a non-negative integer and fits within the range of a 32-bit signed integer.Example 1:n = 5The coins can form the following rows:¤¤ ¤¤ ¤Because the 3rd row is incomplete, we return 2.*///思路,就像高斯定理一样,首项加末项乘香树除以2就是n//解法一 83% 23msint arrangeCoins(int n) { long long int i = n; i = (sqrt(8*i+1)-1)/2; return i;}/解法二 98% 19ms//我试着把long long int 改成float,但是2146467959数据没法通过, 超出了范围,如果改成double就可以了。直接怼到98.65%int arrangeCoins(int n) { double i = n; i = (sqrt(8*i+1)-1)*0.5; return i;}
阅读全文
0 0
- 441_ Arranging_Coins
- ^_^
- ^_^
- ^_^
- ^_^
- *_&
- ...!@~....!@#....+_#%.
- ^_^
- ^_^
- ^_^
- ^_^
- *_*
- ^_^
- ^_^
- ~~~~(>_<)~~~~
- ^_^!
- -_-|||
- ^_^
- 几何板子2
- 轻院1069: 向Z同学学习
- 一起来看MyBatis(三)
- MapReduce I
- Node.js 回调函数(阻塞/非阻塞)学习笔记
- 441_ Arranging_Coins
- 欢迎使用CSDN-markdown编辑器
- hdu1213(基础并查集)
- 字符缓冲输入流的创建
- 堆排序:最大堆与最小堆
- Java基本程序设计结构 入门-简单Java应用
- 单调递增最长子序列LIS(两种解法)
- linux文件系统 EXT2-EXT3的区别
- C语言--struct和union