POJ 1065:wooden Sticks

Source: Internet
Author: User

Greed is a soft rib ...

Do a good brush on the problem.

Or we're going to blow up tomorrow.

Let's all be greedy today.

Well!


Or the sort of a struct. (this thing is really useful!) )

Sort lengths from small to large

If the length is equal then the weight is small in front


Select the first node is not an initial node

Then scan the side array

See those nodes can be processed without processing time

Mark it well.

And then in sequential scan side array

Find the first node without a tag

Do the same scan again.

Loop in turn

See how many times you finish

That is the time of processing


So this sort really is the essence!

I can only say that the knees are rotten ...


L and W mean the opposite, W is the length, L is the weight. #include <iostream> #include <algorithm> #include <stdio.h>using namespace std;struct wood{int w;int l ;} A[5001];bool CMP (wood A,wood b) {//if (A.W = = B.W)//return a.l < b.l;//same length, small weight in front//else//    return A.W < b.w;
   
    return A.w==b.w?a.l < B.L:A.W < B.W;} the int main () {int d[5001];//is used to record the starting point int t,n,ans,i,j;scanf ("%d", &t) of the different sequences, while (t--) {scanf ("%d", &n), and for (i=0;i <n;i++) scanf ("%d%d", &A[I].W,&A[I].L), sort (a,a+n,cmp), or//length first in ascending order, where the weight conflicts will be rescheduled ans = 1;d[0] = a[0].l;/ /first set the first to start for (i=1;i<n;i++) {for (j=0;j<ans;j++) {if (a[i].l >= d[j])//Can be in the back, update {d[j] = A[I].L;   Break;}} if (J==ans)//All starting point does not work, then re-arrange from here a starting point {if (A[i].l < d[j-1]) {d[j] = A[I].L;    Ans + +;}}} printf ("%d\n", ans);}}
   



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ 1065: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.