zoukankan      html  css  js  c++  java
  • Division

    题目链接:https://vjudge.net/problem/UVA-725

    思路:其实就是暴力枚举,但是枚举的时候可以采取些策略减少枚举次数。 因为我们以及知道了 n 和 a,那么我们就可以推出 b ,所以其实我们需要枚举的就是 a ,a 的范围就是[1234,98765]

    这题比较烦的就是对前导0的处理,这里采用 sprintf() 处理前导0 。输出的话就控制一下格式。

    当然调用next_pertation函数好像也可以水过去

     1 #include <cstdio>
     2 #include <cstring>
     3 
     4 bool vis[10];
     5 char str[15];
     6 
     7 bool check(int a, int b)
     8 {
     9     sprintf(str, "%05d%05d", a, b);
    10     memset(vis, 0, sizeof(vis));
    11     for (int i = 0; i < 10; i++)
    12     {
    13         if (vis[str[i]-'0'])  return false;
    14         vis[str[i]-'0'] = true;
    15     }
    16     return true;
    17 }
    18 
    19 int main()
    20 {
    21     int n;
    22     bool first = true;
    23     while (scanf("%d", &n) && n)
    24     {
    25         bool exist = false;
    26         if (first)  first = false;
    27         else  printf("
    ");
    28         for (int i = 1234; i <= 98765; i++)
    29         {
    30             int ans;
    31             if (i % n == 0)
    32             {
    33                 ans = i / n;
    34                 if (ans < 1234)  continue;
    35                 if (check(i, ans))
    36                 {
    37                     exist = true;
    38                     printf("%05d / %05d = %d
    ", i, ans, n);
    39                 }
    40             }
    41         }
    42         if (!exist)  printf("There are no solutions for %d.
    ", n);
    43     }
    44     return 0;
    45 }
  • 相关阅读:
    2879. [NOI2012]美食节【费用流】
    luogu P1012 拼数
    luogu cover
    luogu cogs . [NOIP2003] 传染病控制 WA(1/2)
    luogu P1340 兽径管理 WA
    luogu P1342 请柬
    HTML学习笔记二
    HTML学习笔记一
    arr.sort()
    编写函数实现随机产生指定范围的整数的功能
  • 原文地址:https://www.cnblogs.com/-Ackerman/p/11991950.html
Copyright © 2011-2022 走看看