诡异程序求救

P2782 友好城市

@[ctq1999](/space/show?uid=18673) QAQ~~应该是因为数据比样例还水~~
by Kubic @ 2019-06-07 22:44:31


@[ctq1999](/space/show?uid=18673) 作为一个C++党,你怎么不会lower_bound这个东西呢? 假设数组为a,你保存的是1~n 那么lower_bound (a + 1, a + 1 + n, x) - a 返回的是a数组中第一个大于等于x的数的下标。 upper_bound是第一个大于的,用法同上。
by 梧桐灯 @ 2019-06-07 22:51:35


@[光随影走](/space/show?uid=31193) 不会lower_bound怎么了。。~~我还不会sort+cmp呢~~
by SSerxhs @ 2019-06-07 23:24:22


@[光随影走](/space/show?uid=31193) 谢谢大佬的教导!那样例。。。
by ctq1999 @ 2019-06-08 08:44:43


@[SSerxhs](/space/show?uid=29826) 那你好好学啊~~(话说不会algorithm是怎么红的)~~一定是大佬
by 梧桐灯 @ 2019-06-08 20:20:27


@[ctq1999](/space/show?uid=18673) ```cpp int l = 1, r = n, mid, x; while (l <= r) { mid = l + r >> 1; if (a[mid] >= x) l = mid + 1; else r = mid - 1; } ``` 然后结果是l-1
by 梧桐灯 @ 2019-06-08 20:23:09


@[光随影走](/space/show?uid=31193) 结果不是`mid`吗?
by ctq1999 @ 2019-06-08 20:50:34


@[ctq1999](/space/show?uid=18673) 是这样的,你想l = mid + 1这一语句最后一次被执行时,答案是mid,此时l = mid + 1. 但是以后mid可能改变,但是l不会改变(刚刚说了是最后一次,所以答案是l - 1
by 梧桐灯 @ 2019-06-08 20:53:08


懂了!谢谢大佬讲解!
by ctq1999 @ 2019-06-08 21:34:13


@[光随影走](/space/show?uid=31193)
by ctq1999 @ 2019-06-08 21:34:18


| 下一页