ZOJ Problem Set-1025 Problem Solving report

Source: Internet
Author: User

ZOJ problem Set-1025

  Topic Category: Dynamic planning

  Original title address:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1025

The main idea is that there are lots of wood, each with its own length and weight. Now to process the wood, if the length and weight of a piece of wood is greater than or equal to the length and weight of a piece of wood, it does not take time to process it, otherwise it takes 1 minutes. The length and weight of a pile of wood are now given, requiring the minimum amount of time that can be spent on finishing the pile of wood. For example, 5 wood lengths are given (4,9), (5,2), (2,1), (3,5), (1,4), then the optimal processing sequence is (1,4), (3,5), and (4,9), which only takes two minutes.

Problem-solving ideas: Just read the topic I feel a bit like ascending sequence. This question can be sorted first, sorted by length, with the same length by weight. Then follow the steps below to find out the answer.

(1) Find the first machinable wood of the I∈[1,n (i), and traverse backwards to mark the process without time in this trip and record the number of processed pieces.

(2) If the number of pieces is less than the total number of wood N, then return (1), otherwise enter (3).

(3) The output shortest time is the Traverse number I.

The problem is relatively simple, I have tested the sample data submitted, and then AC.

Code Link:http://paste.ubuntu.com/15263595/

  

1#include <iostream>2 using namespacestd;3 4 structStick5 {6     intLen;7     intWei;8     intmade;9 };Ten intMain () One { A     intT,n,i,j,nowlen,nowwei,count,time; -Stick w[ the],t; -Cin>>T; the      while(T) -     { -Cin>>N; -         if(n = =1) +         { -cout<<"1"<<Endl; +t--; A             Continue; at         } -          for(i=0; i<n;i++) -         { -Cin>>w[i].len>>W[i].wei; -W[i].made =1;//1 means can be machined, 0 means processed -         } in          for(i=0; i<n-1; i++)//Sort -         { to              for(j=i+1;j>0; j--) +             { -                 if(W[j].len < w[j-1].len | | (W[j].len = = W[j].len && W[j].wei <W[j].wei)) the                 { *t =W[j]; $W[J] = w[j-1];Panax Notoginsengw[j-1] =T; -                 } the             } +         } ACount =0;  theTime =0; +          while(Count < N)//Count records the number of pieces that have been processed -         { $              for(i=0; i<n;i++)//record the first machinable wood to be traversed per trip $             { -                 if(W[i].made) -                 { theNowlen =W[i].len; -Nowwei =W[i].wei;Wuyi                      Break; the                 } -             } Wu              for(i=0; i<n;i++)//each traversal can be marked as processed without taking the time -             { About                 if(W[i].len >= nowlen && w[i].wei >= Nowwei &&W[i].made) $                 { -Nowlen =W[i].len; -Nowwei =W[i].wei; -W[i].made =0; Acount++; +  the                 } -             } $time++; the         } thecout<<time<<Endl; thet--; the     } -}

ZOJ Problem Set-1025 Problem Solving report

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.