首页 > 其他 > 详细

P4163 [SCOI2007]排列——next_permutation

时间:2019-10-12 12:17:46      阅读:76      评论:0      收藏:0      [点我收藏+]

P4163 [SCOI2007]排列

 

注意要排序;

next_permutation

 

prev_permutation

 

技术分享图片
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=100;
typedef long long ll;
int T,n,d;
int a[maxn];
char s[maxn];
ll ans;
int main()
{
    scanf("%d",&T);
    while(T--)
    {
        ans=0;
        scanf("%s",s);
        scanf("%d",&d);
        int len=strlen(s);
        for(int i=1;i<=len;i++) a[i]=s[i-1]-0;
        sort(a+1,a+len+1);
        do
        {
            ll sum=0;
            for(int i=1;i<=len;i++)
            {
                sum=sum*10+a[i];
            }
            if(sum%d==0) ans++;
        }while(next_permutation(a+1,a+len+1));
        printf("%lld\n",ans);
    }
    
    return 0;
}
View Code

 

P4163 [SCOI2007]排列——next_permutation

原文:https://www.cnblogs.com/WHFF521/p/11660457.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!