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 ...
随机推荐
- Could not lock surface java.lang.IllegalArgumentException
08-07 14:46:33.795: E/Surface(4927): dequeueBuffer failed (Invalid argument) 08-07 14:46:33.800: E/V ...
- Probability theory
1.Probability mass functions (pmf) and Probability density functions (pdf) pmf 和 pdf 类似,但不同之处在于所适用的分 ...
- LINUX常用命令--重定向、管道篇(四)
一.Linux重定向 重定向能够实现Linux命令的输入输出与文件之间重定向,以及实现将多个命令组合起来实现更加强大的命令.这部分涉及到的比较多的命令主要有: 涉及到的比较多的命令主要有: cat:连 ...
- oracle 高级分组
oracle 高级分组 博客分类: 数据库基础 oraclesql 10.高级分组 本章目标: 对于增强的group by需要掌握: 1.使用rollup(也就是roll up累计的意思)操作产生s ...
- boost库在工作(40)串行通讯
现代的计算机技术进步很快,各种的通讯也日新月异,像USB.网络.蓝牙.WIFI等通讯技术飞速地出现,改变了整个计算机的通讯能力,速度已经达到GBit级别.但是有一种最原始的通讯方式,还是保留了30年, ...
- android:configChanges 屏幕横竖屏切换
出处:http://blog.csdn.net/djy1992/article/details/9378195 ---> android:screenOrientation="por ...
- javascript 中 keyup、keypress和keydown事件
keyup.keypress和keydown事件都是有关于键盘的事件 1. keydown事件在键盘的键被按下的时候触发,keyup 事件在按键被释放的时候触发 keydown.keypress ...
- 面向对象程序设计-C++_课时12访问限制
private: 只有这个类(相同的类,不同的对象也可以)的成员函数可以访问这些成员变量或函数 public: 任何人都可以访问 protected: 只有这个类以及它的子子孙孙可以访问
- transition与visibility与display
http://www.zhangxinxu.com/wordpress/2013/05/transition-visibility-show-hide/ 术语解释是: visibility: 离散步骤 ...
- 662 - Fast Food
描述:状态方程p[i][j]=dp[i-1][k]+dist(k+1,j),由于没搞懂距离dist是怎么计算的,以为是num[j]-num[k+1],结果wa了一次,在状态转移的时候,采用一个数组sc ...