HDU ACM 1051 Wooden Sticks

Source: Internet
Author: User

Test instructions: A machine to handle the board, machine Reset takes 1 minutes, if the next piece of wood length and quality are greater than equal to the previous piece of the machine without resetting, or reset, the start of the machine will take a minute, the shortest time to finish processing the board.

Analysis: first by the length of the wood, if the same length is sorted by quality (from small to large), and then from the go to scan the array, find the matching mark, find a round to look back, until all the planks are marked to the minimum time.

#include <iostream> #include <algorithm>using namespace std; #define N 5005struct a{int w,l;} a[n];bool CMP (a A , A b) {if (A.L<B.L) return True;else if (A.L>B.L) return False;else if (A.W<=B.W) return true;else return false;} BOOL Isuser[n];int Main () {int T,n,i,count,j,k;cin>>t;while (t--) {cin>>n;for (i=0;i<n;i++) cin>> A[i].l>>a[i].w;sort (a,a+n,cmp);              Sort by the length of the planks first, and equal by the quality, from small to large memset (isuser,false,sizeof (IsUser)); Count=0;for (i=0;i<n;i++) {if (!isuser[i]) {count++; K=i;for (j=k+1;j<n;j++) if (!isuser[j] && a[j].l>=a[k].l && a[j].w>=a[k].w) {isuser[k]=true; Isuser[j]=true;k=j;} if (!isuser[k]) isuser[k]=true;}} Cout<<count<<endl;} return 0;}


HDU ACM 1051 Wooden Sticks

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.