HUD 4473 Exam
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4473
题目意思
定义f(x) = 满足(a * b)|x的有序对(a,b)的个数。
然后输入一个n,求f(1) + f(2) + ... + f(n)
废话不多说,此题的关键在于:
把原题的条件(a * b)|x 转化为 a * b * y = x
然后就很好计算了,就是,输入一个n,计算有多少有序对(a, b ,y)满足a*b*y<=n
不妨设a<=b<=y
则,a<=n^(1/3) , b<=sqrt(n/a)
那么
对于三个数字都相同的情况,只计算一次: i i i
对于三个数字中有两个相同的情况,计算3次: i i j, i j i, j i i
对于均不相同的情况,计算6次: a b y ,a y b ,b a y ,b y a, y a b ,y b a
超时代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std; typedef __int64 LL;
const int N=400005;
const LL II=1000000007;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0); LL pow3(LL n)
{
LL p=(LL)pow(n,1.0/3);
while(p*p*p<=n) p++;
while(p*p*p>n) p--;
return p;
} LL pow2(LL n)
{
LL p=(LL)pow(n,1.0/2);
while(p*p<=n) p++;
while(p*p>n) p--;
return p;
} int main()
{
LL n;
int ca=0;
while(~scanf("%I64d",&n))
{
LL m,t,ans=0,i,j,k;
m=pow3(n);t=pow2(n);
for(i=1;i<=m;i++)
for(j=i;j<=t;j++)
for(k=j;k<=n;k++)
{
if(i*j*k>n) continue;
if(i==j&&j==k)
ans++;
else if(i<j&&j<k)
ans+=6;
else
ans+=3;
}
printf("Case %d: %I64d\n",++ca,ans);
}
return 0;
}
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std; typedef __int64 LL;
const int N=400005;
const LL II=1000000007;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0); LL pow3(LL n)
{
LL p=(LL)pow(n,1.0/3);
while(p*p*p<=n) p++;
while(p*p*p>n) p--;
return p;
} LL pow2(LL n)
{
LL p=(LL)pow(n,1.0/2);
while(p*p<=n) p++;
while(p*p>n) p--;
return p;
} int main()
{
LL n;
int ca=0;
while(~scanf("%I64d",&n))
{
LL m,ans=0,i,j;
m=pow3(n);
ans+=m;//第一种,三个相等的情况
for(i=1;i<=m;i++)
{
LL t=n/i;
LL k=pow2(t);
ans+=(t/i+k-i*2)*3;//第二种,前两个相等-后面的比前面的大,或则后两个相同比前面的大
for(j=i+1;j<=k;j++)
ans+=(t/j-j)*6;//第三种,都不相等从小到大
}
printf("Case %d: %I64d\n",++ca,ans);
}
return 0;
}
HUD 4473 Exam的更多相关文章
- HDU 4473 Exam 枚举
原题转化为求a*b*c <=n中选出两个数组成有序对<a,b>的选法数. 令a<=b<=c.... 分情况讨论: (1)全部相等,即a = b = c. 选法有n^(1/ ...
- hdu 4473 Exam 数学
思路: 将条件转化为满足abc<=n的abc的数目. 1.3个数相等时,为 A; 2.有2个数相等时,为 B; 3.都不相等时,为 C. 则结果为A+3*B+6*C. 代码如下: #includ ...
- Linux学习之Exam系统发布
配置时间:2015年11月27日 配置人:撰写人:微冷的雨 Happy 01.Linux安装图 欢迎页面 桌面 02.Linux命令之文件目录操作 给北大青鸟五道口校区创建三个机房(L4,L5,L ...
- 如何用Unity GUI制作HUD
若知其所以然,自然知其然. HUD是指平视显示器,就是套在脸上,和你的眼睛固定在一起,HUD的意思就是界面咯,一般我们说HUD特指把3D空间中的界面的某些信息(比如血条,伤害之类)的贴在界面上,对应3 ...
- xamarin UWP平台下 HUD 自定义弹窗
在我的上一篇博客中我写了一个在xamarin的UWP平台下的自定义弹窗控件.在上篇文章中介绍了一种弹窗的写法,但在实际应用中发现了该方法的不足: 1.当弹窗出现后,我们拖动整个窗口大小的时候,弹窗的窗 ...
- xamarin UWP设置HUD加载功能
使用xamarin开发的时候经常用到加载HUD功能,就是我们常见的一个加载中的动作,Android 下使用 AndHUD , iOS 下使用 BTProgressHUD, 这两个在在 NuGet 上都 ...
- OSG中的HUD
OSG中的HUD 所谓HUD节点,说白了就是无论三维场景中的内容怎么改变,它都能在屏幕上固定位置显示的节点. 实现要点: 关闭光照,不受场景光照影响,所有内容以同一亮度显示 关闭深度测试 调整渲染顺序 ...
- CREATE A ENERGY / HEALTH BAR HUD
Now then, let's get started. 1. Open the Play scene which you had created in the previous post. If y ...
- iOS之UI--指示器HUD的创建和设置
指示器的创建和设置 渐变动画 描述: 使用label就能制作指示器,原理:就是让label以动画的形式慢慢显示和消失 最好是半透明的 指示器有时候也被称为:HUD,遮盖,蒙版 思路步骤: 1.先在st ...
随机推荐
- Flink资料(6) -- 如何添加一个新的Operator
false false false false EN-US ZH-CN X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-n ...
- python request使用
相比httplib.urllib,request真是太美丽了,记录下 下载安装地址:http://docs.python-requests.org/en/latest/user/install/#in ...
- 【Chromium中文文档】Profile架构(看看谷歌家的重构)
进程模型 转载请注明出处:https://ahangchen.gitbooks.io/chromium_doc_zh/content/zh//General_Architecture/Profile_ ...
- sketch 跟随鼠标指针移动的特效
演示地址:http://www.ke01.com/yanshi/sucai/20140830/2/ 下载地址:https://yunpan.cn/cqgWeIYPer8eC 访问密码 672b
- TraceView简单使用方法
一.TraceView简介 TraceView是AndroidSDK里面自带的工具,用于对Android的应用程序以及Framework层的代码进行性能分析. TraceView是图形化的工具,最终它 ...
- 特卖电商俏物悄语或面临破产 ihush域名夭折?:域名新闻:域名门户:eName.CN
特卖电商俏物悄语或面临破产 ihush域名夭折?:域名新闻:域名门户:eName.CN 特卖电商俏物悄语或面临破产 ihush域名夭折?
- nodejs中使用递归案例
var http = require('http'); //1.正常逻辑第一步正常请求,动作进行一次的方法: function seqRequest(i,limit){ var req = http. ...
- Let the Balloon Rise(map)
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- 【每日一摩斯】-Troubleshooting: High CPU Utilization (164768.1) - 系列6
如果问题是一个正运行的缓慢的查询SQL,那么就应该对该查询进行调优,避免它耗费过高的CPU资源.如果它做了许多的hash连接和全表扫描,那么就应该添加索引以提高效率. 下面的文章可以帮助判断查询的问题 ...
- HDU 4937 Lucky Number 规律题_(:зゝ∠)_
把全部合法的进制打出来会发现合法的进制都是在 n/3 n/4 n/5的边上 然后暴力边上的进制数.. #include <cstdio> #include <set> type ...