hdu 2446 Shell Pyramid(GOD = =)
来源:互联网 发布:js array 删除指定元素 编辑:程序博客网 时间:2024/06/10 00:17
开始想打表二分来着,后来想试试能不能推出来公式,结果还真推出来了 = =,很简单的公式。
第n-1堆的最大的序号是,(n*n*n - n)/6。
然后对n*6开立方根可以得到n(细节细节)。。。
再找到这一堆的大小(细节细节)。。
再根据1+2+3。。。求和公式找到第几行(细节细节)。。
再根据前N行的和找到在第N+1行的第几列(细节细节)。。。
= = 。。注意别超unsigned __int64。。中间可以用double计算防超。不过显然数据很小。。
#include <map>#include <set>#include <queue>#include <stack>#include <math.h>#include <time.h>#include <stdio.h>#include <stdlib.h>#include <iostream>#include <limits.h>#include <string.h>#include <string>#include <algorithm>#define MID(x,y) ( ( x + y ) >> 1 )#define L(x) ( x << 1 )#define R(x) ( x << 1 | 1 )#define BUG puts("here!!!")#define STOP system("pause")using namespace std;typedef unsigned __int64 ll;int main(){int ncases;ll n;scanf("%d", &ncases);while( ncases-- ){scanf("%I64u", &n);ll p = (ll)pow(n*6.0, 1.0/3);p++;while( (p*p*p - p) >= n*6.0 ) p--;n -= (p*p*p - p)/6;ll k = (ll)(sqrt(2.0*n));k++;while( k*(k+1)/2 >= n ) k--;ll ans1 = k + 1;ll ans2 = n - k*(k+1)/2;printf("%I64u %I64u %I64u\n", p, ans1, ans2);}return 0;}
- hdu 2446 Shell Pyramid(GOD = =)
- HDU 2446 Shell Pyramid
- HDU 2446 Shell Pyramid
- hdu 2446 Shell Pyramid
- 【二分】 HDU 2446 Shell Pyramid
- HDU 2446 Shell Pyramid(二分查找 数学)
- hdu 2446 Shell Pyramid(数学的东西)
- hdu 2446 Shell Pyramid //二分+二分
- HDU 2446 Shell Pyramid 二分查找
- HDU/HDOJ 2446 Shell Pyramid 2008 Asia Regional Harbin
- Shell Pyramid
- hdu 5432 Pyramid Split(二分)
- Shell Pyramid--tle
- HDU 5432 Pyramid Split
- hdu 5432Pyramid Split
- HDU 5432 Pyramid Split
- HDU - 2809 God of War (DP+状态压缩)
- hdu 2809 God of War
- 这一天终于来了:乔布斯辞职 库克接任
- QFile详解
- Framework Topics:Activities
- linux网络编程并发进程,select和epoll(一)
- 正则表达式30分钟入门教程
- hdu 2446 Shell Pyramid(GOD = =)
- XFire调用CXF服务端,控制台报错
- 假期最后一天
- android pmem 和ashmem 介绍及实例分析
- linux下部署项目一点小经验(原创)
- Unix时间和日期
- oracle 优化器相关知识
- seo 合理应用
- Android代码调试工具 traceview 和 dmtracedump的波折演绎