Yang two elder brother carry the handle

Source: Internet
Author: User

Problem A: Yang Yigo carrying handle time limit:1 Sec Memory limit:128 MB Description

Before the birth of the Sun Wukong, Yang two elder brother has been three of the world, as a carrying handle, not a decent weapon how to do. So two elder brother to Donghalona to oneself and younger brother find weapon. All say local tyrants by equipment, dick Silk by mutation, Yang brothers have such a weapon in the arms of the equipment, the weapons placed in the machine processing, the weight of each weapon (W) and Length (L) has been given, if the transport of the current weapon than the previous weapon of transport length and weight than the previous one, it will not take time, otherwise it takes a minute, Yang Brother's time is very valuable, you need to arrange the order of placement, so that the least time, calculate the number of shipments of n-Weapon of the minimum!

Input

Multiple sets of input data.

Enter N, the number of sticks. n<5000.

Enter W (weight), l (length). 1<w,l<1000000.

Output

The time required for the output.

Sample Input54-432 231 1Sample Output213hint

1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 structnode6 {7     intb;8} a[100001];9 intcmpstructNode A,structNode B)Ten { One     if(a.a==B.A) A         returna.b<b.b; -     returna.a<B.A; -  the } - intMain () - { -     intN; +      while(SCANF ("%d", &n)! =EOF) -     { +         intans=0, flag[100001]= {0}; A          for(intI=0; i<n; i++) atscanf"%d%d",&a[i].a,&a[i].b); -Sort (a,a+n,cmp); -          for(intI=0; i<n; i++) -         { -             if(flag[i]==1) -             { in                 Continue; -             } to           +     for(inti1=i,j=i+1; j<n; J + +) -             { the                 if(a[j].b>=a[i1].b&&flag[j]==0) *                 { $i1=J;Panax Notoginsengflag[j]=1; -                 } the             } +ans++; A         } theprintf"%d\n", ans); +     } -}

Yang two elder brother carry the handle

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.