编程介的小学生 2019-01-13 14:26 采纳率: 20.5%
浏览 476
已采纳

平面直角坐标系上距离点的计算,一个优化的算法,采用C语言谢谢

Problem Description
ACboy is playing a new stone game. There's a rectangular grid board, and some stones placed at the initial location Bi(Xi, Yi) and the targets are at the location Si(Pj, Qj), the time that moving between them is Di,j = |Xi - Pj| + |Yi - Qj| + 1 minutes. And at different places may have different stones, and different target places have different capacity. In the following picture, B1,2,3 stands for the initial places, S1,2,3,4 stands for the target places. In detail, B1(5) means there are 5 stones at this location, S2(4) means you can move at most 4 stones to this target location.

The one who moves the stones from the initial places to the target places using less time will win. So ACboy now telling you his play plan, and you should tell hime whether his plan is the best, or he can do it better.

Input
The input file consists of The game board description and the play plan description. The first line of the input file consists of two numbers N and M separated by a space. N (1 <= N <= 100) is a number of initial places(numbered from 1 to N). M (1 <= M <= 100) is a number of target places(numbered from 1 to M).

The following N lines describe initial places. Each line contains there integer numbers Xi, Yi, and Bi separated by spaces, where Xi, Yi (-1000 <= Xi, Yi <= 1000) are the coordinates of initial places, and Bi (1 <= Bi <= 1000) is the number of stones at this location.

The description of initial places is followed by M lines that describe target places. Each line contains three integer numbers Pj, Qj, and Cj separated by spaces, where Pi, Qi (-1000 <= Pj, Qj <= 1000) are the coordinates of the target places, and Cj (1 <= Cj <= 1000) is the capacity of this place.

The description of the play plan follows on the next N lines. The play plan of ith initial place consists of M integer numbers Ei,j separated by spaces. Ei,j (0 <= Ei, j <= 1000) is a number of stones that shall move from the ith initial place to the jth target place.

The plan in the input file is guaranteed to be valid. Namely, B1+B2+....+Bn <= S1+S2+....+Sn.

Process to the end of file.

Output
If ACboy's plan is the best, print "good", otherwise, print"I can do it better".

Sample Input
2 1
0 0 5
1 1 5
2 2 5
5
0

Sample Output
I can do it better

  • 写回答

1条回答 默认 最新

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

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮