HDU 1099 Lottery (数学问题模拟)
发布日期:2021-11-06 16:56:43
浏览次数:3
分类:技术文章
本文共 3017 字,大约阅读时间需要 10 分钟。
Lottery
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2420 Accepted Submission(s): 1097 Problem Description
Eddy's company publishes a kind of lottery.This set of lottery which are numbered 1 to n, and a set of one of each is required for a prize .With one number per lottery, how many lottery on average are required to make a complete set of n coupons?
Input
Input consists of a sequence of lines each containing a single positive integer n, 1<=n<=22, giving the size of the set of coupons.
Output
For each input line, output the average number of lottery required to collect the complete set of n coupons. If the answer is an integer number, output the number. If the answer is not integer, then output the integer part of the answer followed by a space and then by the proper fraction in the format shown below. The fractional part should be irreducible. There should be no trailing spaces in any line of ouput.
Sample Input
2517
Sample Output
3 511 -- 12 34046358 ------ 720720
有题意可推出n/n+n/(n-1)+n/(n-2)+……n/2+n/1
AC代码:#include#define ll __int64//author:XXYYll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b);}int main(){ ll n,i,m,z,len1,len2,x,n1,n2,y; while(~scanf("%I64d",&n)){ m=0; z=1; for(i=n;i>0;i--){//通分 m=n*z+m*i; z*=i; x=gcd(m,z); m/=x; z/=x; } if(m%z){ y=m/z; m=m%z; n1=y; len1=len2=0; while(n1){ len1++; n1/=10; } n2=z; while(n2){ len2++; n2/=10; } for(i=0;i<=len1;i++) printf(" "); printf("%I64d\n",m); printf("%I64d ",y); for(i=0;i
看到这么小的范围,暴力打表也是可以的:
#includeint main(){ int n; while(~scanf("%d",&n)){ switch(n){ case 1: printf("1\n"); break; case 2: printf("3\n"); break; case 3: printf(" 1\n5 -\n 2\n"); break; case 4: printf(" 1\n8 -\n 3\n"); break; case 5: printf(" 5\n11 --\n 12\n"); break; case 6: printf(" 7\n14 --\n 10\n"); break; case 7: printf(" 3\n18 --\n 20\n"); break; case 8: printf(" 26\n21 --\n 35\n"); break; case 9: printf(" 129\n25 ---\n 280\n"); break; case 10: printf(" 73\n29 ---\n 252\n"); break; case 11: printf(" 551\n33 ----\n 2520\n"); break; case 12: printf(" 551\n37 ----\n 2310\n"); break; case 13: printf(" 9473\n41 -----\n 27720\n"); break; case 14: printf(" 13433\n45 -----\n 25740\n"); break; case 15: printf(" 18581\n49 -----\n 24024\n"); break; case 16: printf(" 4129\n54 -----\n 45045\n"); break; case 17: printf(" 340463\n58 ------\n 720720\n"); break; case 18: printf(" 620743\n62 ------\n 680680\n"); break; case 19: printf(" 1662439\n67 -------\n 4084080\n"); break; case 20: printf(" 3704479\n71 -------\n 3879876\n"); break; case 21: printf(" 408335\n76 ------\n 739024\n"); break; case 22: printf(" 46533\n81 ------\n 235144\n"); break; } } return 0;}
转载地址:https://blog.csdn.net/YJX_xx/article/details/37692169 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
关注你微信了!
[***.104.42.241]2024年04月15日 00时17分13秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
datagrid的正反双向排序
2019-04-27
在分页状态下删除纪录的问题
2019-04-27
使用DataGrid动态绑定DropDownList
2019-04-27
DataGrid删除确认及Item颜色交替
2019-04-27
NetBeans配置Xdebug 远程调试PHP
2019-04-27
MediaWiki安装
2019-04-27
Squid安装
2019-04-27
如何查看当前Linux的版本
2019-04-27
Ubuntu安装Nginx
2019-04-27
Ubuntu 下安装thttpd Web服务器
2019-04-27
用thttpd做Web Server
2019-04-27
服务器端开发经验总结 Linux C语言
2019-04-27
将网站程序放在tmpfs下
2019-04-27
使用Nginx的proxy_cache缓存功能取代Squid
2019-04-27
nginx 反向代理,动静态请求分离,proxy_cache缓存及缓存清除
2019-04-27
nginx 的proxy_cache才是王道
2019-04-27
Nginx proxy_cache 使用示例
2019-04-27
Nginx源代码分析 - 日志处理
2019-04-27
使Apache实现gzip压缩
2019-04-27
Memcached在大型网站中应用
2019-04-27