编程介的小学生 2018-11-20 04:08 采纳率: 20.5%
浏览 372
已采纳

各位大牛,菜鸟又遇到一个C语言的难题,写不出来了

Problem Description
Life on the great oceans has been good for captain Blackbeard and his fellow pirates. They have gathered so many treasures, that each of them is able to buy a house on their favorite island. The houses on this island are all placed in a long row along the beach line of the island. Next to a house, every pirate is also able to buy his own ship to do their own bit of plundering. However, this causes a whole new kind of problem.
Along the beach line there is a long pier where every pirate can park his ship. Although there is enough space along the pier for all the ships, not every pirate will be able to park in front of his house. A pirate is happy with his parking space if some part of the parking space is in front of the center of his house. Captain Blackbeard has been given the diffcult task of assigning the parking spaces to the pirates. A parking space for a pirate i is a range ai, bi along the pier such that li<= bi - ai, where li is the length of the ship of pirate i. Thus, pirate i is happy if ai <= xi <= bi, where xi is the center of the house of pirate i. Clearly, parking spaces of different pirates must be interior disjoint (the ends of ranges can coincide).
Above all, the captain wants a good parking space for himself, so he gives himself the parking space such that the center of his ship is aligned with the center of his house. Next to that, he wants to make as many pirates happy as possible. Can you help him out?

Input
The first line of the input contains a single number: the number of test cases to follow. Each test case has the following format:
1.One line with one integer n (1 <= n <= 1,000): the number of pirates including the captain.
2.n lines with on each line two integers xi (-10^9 <= xi <= 10^9) and li (1 <= li <= 10^9): the center of the house of the ith pirate and the total length of his ship, respectively. The first pirate in the input is always the captain.

Output
For every test case in the input, the output should contain one integer on a single line: the maximum number of happy pirates using an optimal assignment of the parking spaces. This number includes the captain himself. You can assume that the space along the pier is unbounded in both directions.

Sample Input
2
5
0 6
-5 2
-4 1
4 2
5 3
4
0 4
-5 4
3 4
5 3

Sample Output
5
3

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-01-02 15:54
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3