Bzoj1689: [usaco 2005 open] muddy roads

Source: Internet
Author: User
1689: [usaco 2005 open] muddy roadstime limit: 5 sec memory limit: 64 MB
Submit: 147 solved: 107
[Submit] [Status] [discuss] Descriptionfarmer John has a problem: the dirt road from his farm to town has suffered in the recent rainstorms and now contains (1 <= n <= 10,000) mud pools. farmer John has a collection of wooden planks of length L that he can use to bridge these mud pools. he can overlap planks and the ends do not need to be anchored on the ground. however, he must cover each pool completely. given the mud pools, help FJ figure out the minimum number of planks he needs in order to completely cover all the mud pools. input * Line 1: two space-separated integers: N and L * lines 2 .. n + 1: line I + 1 contains two space-separated integers: s_ I and e_ I (0 <= s_ I <e_ I <= 1,000,000,000) that specify the start and end points of a mud pool along the road. the mud pools will not overlap. these numbers specify points, so a mud pool from 35 to 39 can be covered by a single board of length 4. mud pools at (3,6) and (6,9) are not considered to overlap. there are n muds, which are covered with blocks of L length. ask how many blocks are required. output * Line 1: The miminum Number of planks FJ needs to use. sample input3 3
1 6
13 17
8 12

Input details:

FJ needs to use planks of length 3 to cover 3 mud pools. The mud pools
Cover regions 1 to 6, 8 to 12, and 13 to 17.
Sample output5

Output details:

FJ can cover the mud pools with five planks of length 3 in
Following way:
111222... 333444555 ....
. Mmmmm... Mmmm. Mmmm ....
012345678901234567890 hint Source

Silver

Question: This is another question... Consider boundaries and instantly change questions... The first muddy point must be overwritten once as the left endpoint of L, and the rest will continue to consider this... Code:
 1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 #include<cmath> 5 #include<algorithm> 6 #include<iostream> 7 using namespace std; 8 int n,L; 9 struct ken{int l,r;} a[10002];10 bool kp(const ken &i,const ken &j) {return i.l<j.l;}11 void init()12 {13     scanf("%d%d",&n,&L);14     int i;15     for(i=1;i<=n;i++)16        scanf("%d%d",&a[i].l,&a[i].r);17     sort(a+1,a+n+1,kp);18 }19 void work()20 {21     int i,len=0,w=0,ans=0;22     for(i=1;i<=n;i++)23        {if(w>=a[i].r) continue;24         w=max(a[i].l,w);25         while(w<a[i].r) {ans++; w+=L;}26        }27     printf("%d\n",ans);28 }29 int main()30 {31     init(); work();32     return 0;33 }
View code

 

Bzoj1689: [usaco 2005 open] muddy roads

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.