zoukankan      html  css  js  c++  java
  • 枚举专项练习_Uva725(Division)_Uva11059(Maximun Product)

     1 //Uva725
     2 #include <iostream>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <cstdio>
     6 using namespace std;
     7 
     8 void evalu(int n)
     9 {
    10     const int maxn = 1024 + 10;
    11     char num[10];                      //将数字用字符保存
    12     int flag[10];                      //判断每个数,是否重复 
    13     char buf[maxn];                    //将出现的字符全部存到里面 
    14     for (int i = 1234; i <= 5000; i++)
    15     {
    16         memset(flag, 0, sizeof(flag));
    17         memset(num, 0, sizeof(num));
    18         sprintf(num, "%05d", i);
    19 //        cout << "Debug: " << num << endl;
    20 //        system("pause");
    21         int digit = 0, rest = 0;
    22         digit = (num[0]-'0')*10000 + (num[1]-'0')*1000 + (num[2]-'0')*100 + (num[3]-'0')*10 + (num[4]-'0');
    23 //        cout << "Debug:digit: " << digit << endl;
    24 //        system("pause");
    25         rest = digit * n;
    26         sprintf(buf, "%05d%05d", rest, digit);
    27         int len = strlen(buf), j = 0;
    28         for (j = 0; j < len; j++) {
    29             if (flag[buf[j] - '0']) {
    30                 break;
    31             }
    32             else {
    33                 flag[buf[j] - '0'] = 1;
    34             }
    35         }
    36         if (j == len) {
    37             cout << rest << " / " << num << " = " << n << endl;
    38         }
    39     }    
    40 }
    41 
    42 
    43 int main()
    44 {
    45     int num;
    46     while (cin >> num) {
    47         evalu(num);
    48     }    
    49     return 0;
    50 }
     1 //Uva11059
     2 #include <iostream>
     3 #include <vector>
     4 #include <cstdio>
     5 #include <cstdlib>
     6 #include <fstream>
     7 using namespace std;
     8 
     9 //ifstream in("in.txt");
    10 //ofstream out("out.txt");
    11 
    12 int main()
    13 {
    14     long long pro = 1, max_pro = 0;
    15     vector<long long> num;
    16     long long data;
    17     int T, kase = 0;
    18     while (cin >> T) 
    19     {
    20         num.clear();
    21         pro = max_pro = 0;
    22         while (T--) {
    23             cin >> data; num.push_back(data);
    24         }    
    25         for (unsigned i = 0; i < num.size(); i++) {
    26             pro = num[i];
    27             for (unsigned j = i; j < num.size(); j++) {
    28                 if (i != j) {  
    29                     pro *= num[j];            //pro尽管乘 
    30                     if (pro > num[i])         //pro > num[i] 
    31                         num[i] = pro;         //num[i] = pro, 将最大的乘积放到该位置
    32                 }
    33             }
    34         }
    35         for (unsigned i = 0; i < num.size(); i++) {
    36             if (num[i] > max_pro) {
    37                 max_pro = num[i];
    38             }
    39         }
    40         cout << "Case #" << ++kase << ": The maximum product is " << max_pro << "." << "
    
    ";
    41     } 
    42     return 0;
    43 }
    44  
  • 相关阅读:
    洛谷1462 通往奥格瑞玛的道路 二分+spfa
    NumPy 排序、条件刷选函数
    NumPy 统计函数
    2019-3-10——生成对抗网络GAN---生成mnist手写数字图像
    python if __name__ == 'main' 的作用和原理()
    Python os.getcwd()
    numpy.random.uniform()
    tf.trainable_variables()
    tf.layers.dense()
    彻底弄懂tf.Variable、tf.get_variable、tf.variable_scope以及tf.name_scope异同
  • 原文地址:https://www.cnblogs.com/douzujun/p/6309097.html
Copyright © 2011-2022 走看看