zoukankan      html  css  js  c++  java
  • 喷水装置

    题目描述

    思路

    代码

    #include <cstdio>
    #include <cmath>
    
    int n, L, W, t, att, ans;
    double w;
    struct Node {
    	double a, b;
    } arr[15006], tmp;
    inline void read(int &x) {
    	int s = 0, f = 1;
    	char ch = getchar();
    	while (ch < '0' || ch > '9') {
    		if (ch == '-') f = -1;
    		ch = getchar();
    	}
    	while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
    	x = s * f;
    }
    inline void write(int x) {
    	if (x > 9) write(x / 10);
    	putchar(x % 10 + '0');
    }
    void qsort(int L, int R) {
    	int l = L, r = R;
    	double mid = arr[l + r >> 1].a;
    	while (l < r) {
    		while (arr[l].a < mid) l++;
    		while (arr[r].a > mid) r--;
    		if (l <= r) {
    			tmp = arr[l];
    			arr[l] = arr[r];
    			arr[r] = tmp;
    			l++, r--;
    		}
    	}
    	if (l < R) qsort(l, R);
    	if (L < r) qsort(L, r);
    }
    int main() {
    	read(t);
    	while (t--) {
    		ans = 0, att = 0;
    		read(n), read(L), read(W);
    		double w = W / 2.0, ww = w * w, wx;
    		
    		for (int i = 1, a, b; i <= n; ++i) {
    			read(a), read(b);
    			if (b <= w) continue;
    			wx = sqrt(b * b - ww);
    			arr[++att].a = a - wx;
    			arr[att].b = a + wx;
    		}
    		qsort(1, att);
    		double ta = 0.0, tb = 0.0, prea = 0, preb;
    		while (ta < L) {
    			tb = ta;
    			for (int i = prea + 1; i <= att; ++i) {
    				if (arr[i].a <= ta && arr[i].b > tb) {
    					tb = arr[i].b;
    					preb = i;
    				} 
    			}
    			ans++;
    			if (prea == preb) break;
    			ta = tb, prea = preb;
    		}
    		if (ta >= L) write(ans), puts("");
    		else puts("-1");
    	}
    	return 0;
    }
    
  • 相关阅读:
    彻底弄懂最短路径问题[转]
    activiti任务TASK
    linux查看磁盘空间
    Introduction to the POM
    【转】10 个迅速提升你 Git 水平的提示
    macbook安装mysql
    java并发编程之美-笔记
    springboot2精髓读书笔记
    java多线程
    实战JAVA虚拟机笔记
  • 原文地址:https://www.cnblogs.com/liuzz-20180701/p/11556999.html
Copyright © 2011-2022 走看看