UVa 324 - Factorial Frequencies
来源:互联网 发布:中班美工剪纸 编辑:程序博客网 时间:2024/06/10 22:55
题目:计算n!每位上的数字出现的次数。
分析:简单题、模拟。大数计算,先计算大数阶乘,然后统计即可。
注意:366!有760位左右,注意数组大小。
#include <stdio.h>#include <stdlib.h>#include <string.h>int ans[ 201 ];int bit[ 10 ];void countbit( int f, int v ){if ( !f ) {while ( v ) {bit[v%10] ++;v /= 10;}}else {for ( int i = 0 ; i < 4 ; ++ i ) {bit[v%10] ++;v /= 10;}}}int main(){int N;while ( scanf("%d",&N) && N ) {memset( ans, 0, sizeof(ans) );memset( bit, 0, sizeof(bit) );ans[0] = 1;for ( int i = 2 ; i <= N ; ++ i ) {for ( int j = 0 ; j < 200 ; ++ j )ans[j] *= i;for ( int j = 0 ; j < 200 ; ++ j )if ( ans[j] >= 10000 ) {ans[j+1] += ans[j]/10000;ans[ j ] %= 10000;}}int end = 200;while ( end > 0 && !ans[end] ) -- end;countbit( 0, ans[end --] );while ( end >= 0 ) countbit( 1, ans[end --] );printf("%d! --\n",N);for ( int i = 0 ; i < 10 ; ++ i ) {printf(" (%d)%5d",i,bit[i]);if ( i%5 == 4 ) printf("\n");else printf(" ");}}return 0;}
- UVa 324 - Factorial Frequencies
- uva 324Factorial Frequencies
- UVa 324 Factorial Frequencies (高精度)
- Factorial Frequencies
- POJ 1454 Factorial Frequencies 笔记
- UVa 10062 - Tell me the frequencies!
- UVA 10062 Tell me the frequencies!
- UVa:884 Factorial Factors
- UVa 884 - Factorial Factors
- UVa 12955 Factorial
- UVA - 884 Factorial Factors
- Uva 12934 Factorial Division
- UVa 10323 - Factorial! You Must be Kidding!!!
- [简单DP][完全背包]UVA 12955 Factorial
- UVA - 10856 Recover Factorial(二分查找)
- Factorial!
- Factorial
- Factorial
- 微软面试智力题
- 2011斯坦福大学iOS应用开发教程学习笔记(第五课)Protocols,手势识别
- ora.rac1.LISTENER_RAC1.lsnr` on member `rac1` has experienced an unrecoverable failure
- OpenGL ES 01]OpenGL ES之初体验
- kernel tips
- UVa 324 - Factorial Frequencies
- Fibnacci序列(递归)
- Web Dicom Viewer
- Windows Media Service9
- Windows Media Service网络电台服务器架设教程
- IOS or Android
- DMA工作原理
- UML学习笔记(三)【序列图】(时序图、交互图)
- 小酌人生之党支部会议