• HDU 1716 排列2


    排列2

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 8865    Accepted Submission(s): 3272

    Problem Description
    Ray又对数字的列产生了兴趣:
    现有四张卡片,用这四张卡片能排列出很多不同的4位数,要求按从小到大的顺序输出这些4位数。
    Input
    每组数据占一行,代表四张卡片上的数字(0<=数字<=9),如果四张卡片都是0,则输入结束。
     
    Output
    对每组卡片按从小到大的顺序输出所有能由这四张卡片组成的4位数,千位数字相同的在同一行,同一行中每个四位数间用空格分隔。
    每组输出数据间空一行,最后一组数据后面没有空行。
     
    Sample Input
    1 2 3 4
    1 1 2 3
    0 1 2 3
    0 0 0 0
     
    Sample Output
    1234 1243 1324 1342 1423 1432
    2134 2143 2314 2341 2413 2431
    3124 3142 3214 3241 3412 3421
    4123 4132 4213 4231 4312 4321
     
    1123 1132 1213 1231 1312 1321
    2113 2131 2311
    3112 3121 3211
     
    1023 1032 1203 1230 1302 1320
    2013 2031 2103 2130 2301 2310
    3012 3021 3102 3120 3201 3210
    排列,注意规则
    #include <iostream> 
    #include <algorithm> 
    #include <cstring> 
    #include <cstdio>
    #include <vector> 
    #include <queue> 
    #include <cstdlib> 
    #include <iomanip>
    #include <cmath> 
    #include <ctime> 
    #include <map> 
    #include <set> 
    using namespace std; 
    #define lowbit(x) (x&(-x)) 
    #define max(x,y) (x>y?x:y) 
    #define min(x,y) (x<y?x:y) 
    #define MAX 100000000000000000 
    #define MOD 1000000007
    #define pi acos(-1.0) 
    #define ei exp(1) 
    #define PI 3.141592653589793238462
    #define ios() ios::sync_with_stdio(false)
    #define INF 0x3f3f3f3f 
    #define mem(a) (memset(a,0,sizeof(a))) 
    typedef long long ll;
    set<int>s[10];
    int a[5];
    int main()
    {
        int ok=0;
        while(scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3])&& (a[0],a[1],a[2],a[3]))
        {
            if(ok) printf("
    ");
            ok++;
            for(int i=0;i<10;i++) s[i].clear();
            do{
                if(a[0]==0) continue;
                int ans=0;
                for(int i=0;i<4;i++)
                {
                    ans=ans*10+a[i];
                }
                s[a[0]].insert(ans);
            }while(next_permutation(a,a+4));
            for(int i=1;i<10;i++)
            {
                if(s[i].size()==0) continue;
                bool flag=true;
                for(set<int>::iterator it=s[i].begin();it!=s[i].end();it++)
                {
                    if(!flag) printf(" ");
                    printf("%d",*it);
                    flag=false;
                }
                printf("
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    $route 侦听路由参数的变化
    vue移动端(持续更新......)
    vue本地开发配置及项目部署
    vue解决虚拟dom复用的问题
    移动端头部固定中间内容滚动
    VUE的路由懒加载及组件懒加载
    VUEX(状态管理)之憨憨篇
    Go-第一篇
    高精度1
    牛客练习赛61
  • 原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7283584.html
Copyright © 2020-2023  润新知