本文主要是介绍Highway UVA - 1615,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
模拟,把每个点在S上的作用区间找到。
这道题疯狂runtime error,结果还是数组开小了,下次长记性了(;
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;struct node {double l;double r;
} p[10000];int s;
int d;
int n;
int ans;
node t;bool cmp(node & a, node & b){if (a.l == b.l) {return a.r < b.r;}return a.l < b.l;
}int main() {// freopen("input.txt", "r", stdin);int x, y;while(~scanf("%d", &s)) {scanf("%d", &d);scanf("%d", &n);for(int i = 0; i < n; i++) {scanf("%d%d", &x, &y);double r = sqrt((double)abs((double)(d * d - y * y)));p[i].l = 0 >= (x - r) ? 0 : x - r;p[i].r = s <= (x + r) ? s : x + r;}sort(p, p+n, cmp);ans = 1;t.l = p[0].l;t.r = p[0].r;for(int i = 1; i < n; i++) {if (t.r < p[i].l) {ans++;t.l = p[i].l;t.r = p[i].r;}else {t.l = p[i].l;t.r = min(t.r, p[i].r);}}printf("%d\n", ans);}return 0;
}
这篇关于Highway UVA - 1615的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!