1042 N!

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<string>
 4 using namespace std;
 5 const int MAX=5000;
 6 int array[MAX+5];
 7
 8 int main()
 9 {
10     int n;int i,j;
11     while(cin>>n)
12     {
13
14         memset(array,0,sizeof(array));
15         array[0]=1;
16
17
18
19          for ( i=2 ; i<=n; i++)
20         {
21             int c=0;
22             for ( j=0; j<MAX; j++)
23             {
24                 int s=array[j]*i+c;
25                 array[j]=s%100000;
26                 c=s/100000;
27             }
28         }
29
30
31         for ( j=MAX-1; j>=0; j--)
32             if (array[j])
33                 break;
34         printf("%d",array[j]);
35         for ( i=j-1; i>=0; i--)
36             printf("%05d",array[i]);
37         printf("\n");
38     }
39 return 0;
40 }

 

N!

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 58167    Accepted Submission(s): 16520

Problem Description

Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!

Input

One N in one line, process to the end of file.

Output

For each N, output N! in one line.

Sample Input

1 2 3

Sample Output

1 2 6

对这题已经彻底无语了。已经断断续续一个多月了。

2点注意:

1 数组大小 8000(7000不行)

2 一个数组元素存一个五位数。输出时。不够五位数的前面加零。想想为什么。

时间: 2024-08-06 09:41:29

1042 N!的相关文章

问题 1042: C语言程序设计教程(第三版)课后习题9.10

/******************************************************************** @file Main.cpp @date 2017-05-28 22:10:10 @author Zoro_Tiger @brief 问题 1042: C语言程序设计教程(第三版)课后习题9.10 http://www.dotcpp.com/oj/problem1042.html ***************************************

[BZOJ 1042][HAOI 2008]硬币购物(背包+容斥原理)

题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1042 刚开始搞容斥原理,还很有点吃力,我太弱了... 首先用被类似于背包的DP进行预处理,假设每种硬币个数无限制,求出f[i]=凑出面值i的方案总数. 但是实际上题目中每种硬币个数是有限制的,设四种硬币分别是a.b.c.d,则凑出面值S的方案中超出限制的方案数=a超出限制的方案数+b超出限制的方案数+c超出限制的方案数+d超出限制的方案数-a和b都超出限制的方案数-a和c都超出限

BZOJ 1042 硬币购物(完全背包+DP)

题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1042 题意:给出四种面值的硬币c1,c2,c3,c4.n个询问.每次询问用d1.d2.d3.d4个相应的硬币能够拼出多少种总和为s? 思路:(1)首先,用完全背包求出f[i]表示四种硬币的数量无限制拼出i的方案数. (2)接着我们来理解 x=f[s]-f[s-(d1+1)*c1]的含义:x表示c1硬币的数量不超过d1个而其他三种硬币的数量不限制拼成s的方案数.我们举着例子来说明, 假设

HDU 1042 N!

题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1042Problem DescriptionGiven an integer N(0 ≤ N ≤ 10000), your task is to calculate N! InputOne N in one line, process to the end of file. OutputFor each N, output N! in one line. Sample Input123 Sample

【1042】智商是硬伤

唉,还没坚持一下下怎么就能说自己不行 我的改了一天都没改好,到了晚上都没耐心再改了.这么蒟蒻道题,我能做这么久真是能耐 先上刘汝佳版标准代码 1 //hdoj1042.cpp 2 #include<iostream> 3 #include<string> 4 using namespace std; 5 const int MAXN=36000;//求10000!数组要36000才行 6 7 int a[MAXN]; 8 int main(){ 9 int n,i,j; 10 wh

[BZOJ 1042] [HAOI2008] 硬币购物 【DP + 容斥】

题目链接:BZOJ - 1042 题目分析 首先 Orz Hzwer ,代码题解都是看的他的 blog. 这道题首先使用DP预处理,先求出,在不考虑每种硬币个数的限制的情况下,每个钱数有多少种拼凑方案. 为了避免重复的方案被转移,所以我们以硬币种类为第一层循环,这样阶段性的增加硬币. 一定要注意这个第一层循环要是硬币种类,并且初始 f[0] = 1. f[0] = 1; for (int i = 1; i <= 4; ++i) { for (int j = B[i]; j <= MaxS; +

msyql主从复制 Last_IO_Errno: 1042

在slave服务器上执行 show slave status\G 时的报错: Seconds_Behind_Master: NULLMaster_SSL_Verify_Server_Cert: No                Last_IO_Errno: 1042                Last_IO_Error: error connecting to master '[email protected]:3306' - retry-time: 60  retries: 86400 

HLJU 1042 Fight (种类并查集)

1042: Fight Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 26  Solved: 8 [Submit][Status][Web Board] Description 虽然格斗是非常需要技术的一项运动,但是打群架却不需要什么技术,而且场面一般比较混乱,分不清谁和谁是一伙的,只能看出谁和谁不是一伙的,而且打群架经常会出现猪一样的队友,误伤自己人.现在给你一些信息,请你依据这些信息判断是否一定存在猪一样的队友. Input 包含多组测试样例

BZOJ 1042 硬币购物

Description 硬币购物一共有4种硬币.面值分别为c1,c2,c3,c4.某人去商店买东西,去了tot次.每次带di枚ci硬币,买si的价值的东西.请问每次有多少种付款方法. Input 第一行 c1,c2,c3,c4,tot 下面tot行 d1,d2,d3,d4,s Output 每次的方法数 Sample Input 1 2 5 10 2 3 2 3 1 10 1000 2 2 2 900 Sample Output 4 27 HINT 数据规模 di,s<=100000 tot<

1042. Shuffling Machine

1042. Shuffling Machine (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid "inside