T9的空间

You will never walk alone!

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  69 随笔 :: 0 文章 :: 28 评论 :: 0 Trackbacks
http://acm.pku.cn/JudgeOnline/problem?id=3187
Source Code

Problem: 
3187  User: Torres 
Memory: 404K  Time: 94MS 
Language: G
++  Result: Accepted 

Source Code 
#include
<iostream>
#include
<string>
#include
<algorithm>

using namespace std;

int main()
{
    
int N,S,a[10],b[10];
    
int i,j;
    scanf(
"%d%d",&N,&S);
    
for(i=0;i<N;i++) a[i]=i+1;
    
do
    
{
        memcpy(b,a,
sizeof(a));
        j
=N;
        
while(j--)
        
{
            
for(i=0;i<j;i++)
                b[i]
+=b[i+1];
        }

        
if(b[0]==S) break;
    }
while(next_permutation(a,a+N));
    
for(i=0;i<N;i++)
        printf(
"%d ",a[i]);
    printf(
"\n");
    
return 0;
}

http://acm.pku.cn/JudgeOnline/problem?id=3187

题意很好理解,看样例便可以懂,又一次用STL偷懒了,不过在N很小的情况下,很方便。
posted on 2008-10-22 17:25 Torres 阅读(616) 评论(1)  编辑 收藏 引用 所属分类: Number Theory

评论

# re: POJ 3187 (next_permutation) 2008-10-22 20:09 航哥哥
小子,加油~~~
哥哥支持你~~~  回复  更多评论
  


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理