| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 559 人关注过本帖
标题:如何把时间缩短到一秒以内
只看楼主 加入收藏
欣飞飞
Rank: 1
等 级:新手上路
帖 子:20
专家分:1
注 册:2013-10-6
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:4 
如何把时间缩短到一秒以内
#include<iostream>
using namespace std;
int main()
{
    int n,m,r;
    __int64 k=1,q=1;
    while(cin>>n>>m)
    {
        if(n==0&&m==0) break;
        for(int j=n+m;j>n;j--)
        {
            q*=j;
        }
        for(int p=m;p>=1;p--)
        {
            k*=p;
        }
    r=q/k;
    cout<<r<<endl;
    }
    return 0;
}
搜索更多相关主题的帖子: 如何 
2013-10-13 15:59
欣飞飞
Rank: 1
等 级:新手上路
帖 子:20
专家分:1
注 册:2013-10-6
收藏
得分:0 
Imagine you are attending your math lesson at school. Once again, you are bored because your teacher tells things that you already mastered years ago (this time he's explaining that (a+b)2=a2+2ab+b2). So you decide to waste your time with drawing modern art instead.

Fortunately you have a piece of squared paper and you choose a rectangle of size n*m on the paper. Let's call this rectangle together with the lines it contains a grid. Starting at the lower left corner of the grid, you move your pencil to the upper right corner, taking care that it stays on the lines and moves only to the right or up. The result is shown on the left:



Really a masterpiece, isn't it? Repeating the procedure one more time, you arrive with the picture shown on the right. Now you wonder: how many different works of art can you produce?
 

Input
The input contains several testcases. Each is specified by two unsigned 32-bit integers n and m, denoting the size of the rectangle. As you can observe, the number of lines of the corresponding grid is one more in each dimension. Input is terminated by n=m=0.
 

Output
For each test case output on a line the number of different art works that can be generated using the procedure described above. That is, how many paths are there on a grid where each step of the path consists of moving one unit to the right or one unit up? You may safely assume that this number fits into a 32-bit unsigned integer.
 
图片附件: 游客没有浏览图片的权限,请 登录注册
2013-10-13 16:10
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:4 
第一,你应该将那个东拉西扯废话连篇的洋文翻译成中文,这是人品问题
第二,题目中说的是 unsigned 32-bit integer,你代码中写的是什么?
第三,凭什么你认为__int64就不会溢出?我随便举个例子,比如 15*15 的格式一共有155117520种路径。
15、15、155117520 都在 32-bit unsigned integer 之内,但你的算法中途__int64就溢出了(换成 uint64_t也一样)。
2013-10-14 10:39
吾名衍
Rank: 2
等 级:论坛游民
帖 子:1
专家分:16
注 册:2013-10-4
收藏
得分:16 
#include <iostream>
using namespace std;
double CNM(unsigned int N, unsigned int M)
{
    M = (M > N - M) ? N - M : M;
    double ret = 1;
    while(M > 0)ret *= double(N--) / double (M--);
    return ret;
}
int main(int argc, char* argv[])
{
    unsigned int A, B;
    while(scanf("%d %d", &A, &B) && !(A == 0 && B == 0))
        printf("%.0lf\n",CNM(A + B, B));
    return 0;
}
2013-10-16 14:39
你若复变
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-10-16
收藏
得分:0 
程序运行不了 的说
2013-10-16 17:16
快速回复:如何把时间缩短到一秒以内
数据加载中...
 
   



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

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