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