• 1614Shredding Company


    我的错误代码

    #include "iostream"
    #include "math.h"
    #include "algorithm"
    #define N 100000;
    using namespace std;
    int total,list[1000],n,m,MIN,top,step,data[1000];
    
    void dfs(int a){
      int i,j,num;
      if(total>m)return;
      if(m-total<MIN&&a==top){MIN=m-total;}
      for(i=a;i<top;i++){
        num=0;
        for(j=a;j<=i;j++){
          num=num+list[j]*pow(10,j-a);
        }
        total+=num;
        //cout<<a<<' '<<num<<' '<<total<<endl;system("pause");
        dfs(i+1);
        total-=num;
      }
    }
    
    int main(){
      int i;
      while(cin>>m>>n&&m&&n){
        top=1;step=1;
        while(n){
          list[top++]=n%10;
          n=n/10;
        }
        MIN=N;
        dfs(1);
        cout<<m-MIN<<endl;
      }
    }

    人家的代码

    // POJ1416.cpp : Defines the entry point for the console application.
    //
    
    #include <iostream>
    #include <iterator>
    #include <string>
    using namespace std;
    
    static int clonum;
    static bool repeat;
    static int sh[20];
    static int stps;
    void DFS(const string& num, int beg, int end, int cnt, int t, int stp, int shredded[20])
    {
        int cutnum = 0;
        if (end == num.size())
        {
            for (int i = beg; i < end; ++i) cutnum = cutnum * 10 + (num[i]-'0');
            cnt += cutnum;
            if (cnt == clonum)repeat = true;
            else if(cnt <= t && cnt > clonum)
            {
                shredded[stp] = cutnum;
                copy(&shredded[0],&shredded[stp + 1], &sh[0]);
                clonum = cnt;
                stps = stp;
                repeat = false;
            }
        }
        else
        {
            DFS(num, beg, end + 1, cnt, t, stp, shredded);
            for (int i = beg; i < end; ++i) cutnum = cutnum * 10 + (num[i]-'0');
            if (cnt + cutnum <= t)
            {
                shredded[stp] = cutnum;            
                DFS(num, end, end + 1, cnt + cutnum, t, stp + 1, shredded);
            }
        }
    }
    int main(int argc, char* argv[])
    {
        int t;
        string num;
        while (cin >> t >> num && t != 0 && num != "0")
        {
            int n;
            sscanf(num.c_str(),"%d",&n);
            if (n == t)
            {
                cout << t <<" " << n << endl;
                continue;
            }
            n = 0;
            for (int i = 0; i < num.size(); ++i) n += num[i] - '0';
            if (n > t )
            {
                cout << "error
    ";
                continue;
            }
            clonum = 0;
            repeat = false;
            int shredded[20];
            memset(shredded, 0, sizeof(shredded));
            DFS(num, 0, 1, 0, t, 0,shredded);
            if (repeat == true) cout << "rejected
    ";
            else
            {
                cout << clonum << " ";
                copy(&sh[0], &sh[stps + 1], ostream_iterator<int>(cout," "));
                cout<<endl;
            }
        }
        return 0;
    }
  • 相关阅读:
    Web服务器安全设置
    java大文件读写操作,java nio 之MappedByteBuffer,高效文件/内存映射
    Java IO和Java NIO在文件拷贝上的性能差异分析
    Java高效读取大文件
    NIO入门之轻松读取大文件
    我来说说java的NIO
    java读取大文件 超大文件的几种方法
    @RequestBody 的正确使用办法
    友鱼项目知识点
    怎样查看Tomcat动态控制台信息
  • 原文地址:https://www.cnblogs.com/dowson/p/3349613.html
Copyright © 2020-2023  润新知