| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1173 人关注过本帖
标题:关于大数据考虑不充分可能导致内存越界的问题,程序运行时发生崩溃~求高手解 ...
只看楼主 加入收藏
阿汤跑江湖
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-2-21
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:8 
关于大数据考虑不充分可能导致内存越界的问题,程序运行时发生崩溃~求高手解答!
In how many ways can you choose k elements out of n elements, not taking order into account?

Write a program to compute this number.
Input Specification
The input file will contain one or more test cases.

Each test case consists of one line containing two integers n () and k ( ).

Input is terminated by two zeroes for n and k.
Output Specification
For each test case, print one line containing the required number. This number will always fit into an integer, i.e. it will be less than 231.


Warning: Don't underestimate the problem. The result will fit into an integer - but if all intermediate results arising during the computation will also fit into an integer depends on your algorithm. The test cases will go to the limit.我的代码如下:#include<iostream>
using namespace std;
long F(int);
int main()
{
    int n,k;
    while(1)
    {
        cin>>n>>k;
        if(n==0&&k==0) break;
        else
            cout<<F(n)/(F(k)*F(n-k))<<endl;
    }
    return 0;
}
 long F(int m)
{
    int sum=1,i;
    for(i=1;i<=m;i++)
        sum=sum*i;
    return(sum);
}
求高手解答:当我输入49和6之后运行发生崩溃,可能是内存越界了,没有考虑到大数据,该怎么改???急啊~~
 
搜索更多相关主题的帖子: one will account required elements 
2012-03-18 20:32
zd1505675319
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:139
专家分:178
注 册:2011-11-4
收藏
得分:3 
这个是计算组合数的 程序吧。。
2012-03-18 21:11
czz5242199
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:4
帖 子:660
专家分:2400
注 册:2011-10-26
收藏
得分:6 
C(n,k)=C(n-1,k)+C(n-1,k-1)

大数运算
2012-03-18 21:14
nicum
Rank: 8Rank: 8
等 级:蝙蝠侠
帖 子:180
专家分:712
注 册:2011-2-1
收藏
得分:3 
一个int 4个字节,能保存的最大整数 4 294 967 296,49!=6*10^62,早就越界了
2012-03-18 22:06
阿汤跑江湖
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-2-21
收藏
得分:0 
回复 2楼 zd1505675319
是的啊,但是改怎么来处理数据越界的问题呢?
2012-03-19 00:57
阿汤跑江湖
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-2-21
收藏
得分:0 
回复 3楼 czz5242199
你指的是用递归来处理吗?但是算出的结果应该是一样的,还是会溢出啊?
2012-03-19 00:58
阿汤跑江湖
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-2-21
收藏
得分:0 
回复 4楼 nicum
所以我才问该怎么处理嘛~~~
2012-03-19 00:59
czz5242199
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:4
帖 子:660
专家分:2400
注 册:2011-10-26
收藏
得分:8 
大数运算,即用数组来存储数的每一位,然后用循环模拟加减乘法和进位
2012-03-19 00:59
阿汤跑江湖
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-2-21
收藏
得分:0 
回复 8楼 czz5242199
挺复杂的说,,,,,能给个类似的代码例子吗?谢谢啦!
2012-03-20 22:13
快速回复:关于大数据考虑不充分可能导致内存越界的问题,程序运行时发生崩溃~求 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021939 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved