1029: [JSOI2007] Building repair time limit:4 Sec Memory limit:162 MB
submit:2285 solved:1004
[Submit] [Status] Description
Xiao Gang is playing a computer game called "Building Repair" provided by Jsoi: After a fierce battle, the T tribe destroyed all the invaders of the Z tribe. But there are already n construction facilities in the T tribe's base that have been severely damaged, and if not repaired soon, the construction facilities will be completely destroyed. Now the situation is: there is only one repairman at the base of the T tribe, although he can get to any building in an instant, but repairing each building will take some time. At the same time, the repairman repaired a building to repair the next building, unable to repair multiple buildings at the same time. If a building has not been completely repaired for a period of time, the building will be scrapped. Your mission is to help small just make a reasonable order of repairs to repair as many buildings as possible.
Input
The first line is an integer n, and the next n rows of two integers per line t1,t2 describe a building: it takes T1 seconds to repair the building, and if it is not repaired within T2 seconds, the building is scrapped.
Output
Output an integer s, which means that a maximum of s buildings can be repaired. Data range: N<150000,T1
Sample Input4
100 200
200 1300
1000 1250
3200Sample Output3without a glance at the essence ... We do this: Sort by end time first,now the time now+ lasts <= end time, then ans++;else we replace the previous maximum duration with the current task, if the maximum duration of the previous task now-+ the current duration, the calculation task is replaced. Think about:now it's reduced, that's greed. You can use heap maintenance to find the maximum value of a task. The code is still very short.
1 1029: [JSOI2007] Construction repair2 3Time Limit:4Sec Memory Limit:162MB4Submit:2285Solved:10045 [Submit][status]6 Description7 8 Xiao Gang is playing a computer game called "Building Repair" provided by Jsoi: After a fierce battle, the T tribe destroyed all the invaders of the Z tribe. But there are already n construction facilities in the T tribe's base that have been severely damaged, and if not repaired soon, the construction facilities will be completely destroyed. Now the situation is: there is only one repairman at the base of the T tribe, although he can get to any building in an instant, but repairing each building will take some time. At the same time, the repairman repaired a building to repair the next building, unable to repair multiple buildings at the same time. If a building has not been completely repaired for a period of time, the building will be scrapped. Your mission is to help small just make a reasonable order of repairs to repair as many buildings as possible. 9 Ten Input One A The first line is an integer n, and the next n rows of two integers per line t1,t2 describe a building: it takes T1 seconds to repair the building, and if it is not repaired within T2 seconds, the building is scrapped. - - Output the -Output an integer s, which means that a maximum of s buildings can be repaired. Data range: n<150000, T1 - - Sample Input + - 4 + A - $ at - $ 1300 - - + 1250 - - - 3200 in Sample Output - to 3
View Code
Bzoj 1029 [JSOI2007] construction repair (greed)