zoukankan      html  css  js  c++  java
  • 2020CCPC秦皇岛 C- Cameraman

    水题
    当时没时间了,时间分配还是有问题

    把点投影到四边形上,计算到某个顶点的距离,排序

    #include<bits/stdc++.h>
    using namespace std;
    
    const double pi = acos(-1.0);
    const int N = 1e5 + 10;
    double a1, a2, a3, a4;
    int T, w, h, n;
    int bx, by;
    double angle(int x, int y) {
    	return atan2(y - by, x - bx);
    }
    struct Point {
    	int x, y;
    }A[N];
    double cal_p(double a) {
    	if (a < a1 or a >= a4) {
    		return h - by + tan(a) * bx;
    	}
    	if (a >= a1 and a < a2) {
    		a += pi / 2;
    		return h + bx + tan(a) * by;
    	}
    	if (a >= a2 and a < a3) {
    		return w + h + by + tan(a) * (w - bx);
    	}
    	if (a >= a3 and a < a4) {
    		a -= pi / 2;
    		return w - bx + tan(a) * (h - by) + 2 * h + w;
    	}
    }
    
    double d[N];
    int main() {
    	scanf("%d", &T);
    	for (int c = 1; c <= T; c++) {
    		scanf("%d%d", &w, &h);
    		scanf("%d%d", &bx, &by);
    		a1 = angle(0, 0), a2 = angle(w, 0), a3 = angle(w, h), a4 = angle(0, h);
    		scanf("%d", &n);
    		for (int i = 0; i < n; i++)scanf("%d%d", &A[i].x, &A[i].y);
    
    		for (int i = 0; i < n; i++) {
    			d[i] = cal_p(angle(A[i].x, A[i].y));
    		}
    		sort(d, d + n);
    		double ans = 2 * w + 2 * h - d[n - 1] + d[0];
    		for (int i = 1; i < n; i++) {
    			ans = max(ans, d[i] - d[i - 1]);
    		}
    		printf("Case #%d: %.8f
    ", c, ans);
    	}
    }
    
    
  • 相关阅读:
    当今的架构师和架构
    外企2
    测试驱动开发TDD系列
    在IIS中部署WCF中遇到的问题
    设计高可用和高负载的网站系统(转载)
    IIS中部署WCF
    无限级分类1
    读《WCF技术剖析》(卷一)
    无限极列表2
    TCP/IP、HTTP、WEBSERVICE、SOAP、ICE都使用后才有感慨
  • 原文地址:https://www.cnblogs.com/sduwh/p/13856843.html
Copyright © 2011-2022 走看看