UVa 1643 Angle and Squares (计算几何)

题意:有n个正方形和一个角(均在第一象限中),使这些正方形与这个角构成封闭的阴影区域,求阴影区域面积的最大值。

析:很容易知道只有所有的正方形的对角形在一条直线时,是最大的,然后根据数学关系,就容易得到答案。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define print(a) printf("%d\n", (a))
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e3 + 5;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
    return r >= 0 && r < n && c >= 0 && c < m;
}

int main(){
    double sq, s, ax, ay, bx, by;
    while(scanf("%d", &n) && n){
        cin >> ax >> ay >> bx >> by;
        sq = 0.0, s = 0.0;
        for(int i = 0; i < n; i++){
            double m;   cin >> m;
            s += m * m;
            sq += m;
        }
        double k1 = ay / ax, k2 = by / bx;
        double x1 = fabs((k2+1)*sq/(k2-k1)),  y1 = k1*x1;
        double x2 = fabs((k1+1)*sq/(k2-k1)),  y2 = k2*x2;
        double area = fabs((x1*y2 - x2*y1) / 2.0);
        double sum = area - s/2.0;
        printf("%.3lf\n", sum);
    }
    return 0;
}
时间: 2024-10-29 10:46:26

UVa 1643 Angle and Squares (计算几何)的相关文章

UVA - 1643 Angle and Squares (角度和正方形)(几何)

题意:第一象限里有一个角,把n(n <= 10)个给定边长的正方形摆在这个角里(角度任意),使得阴影部分面积尽量大. 分析:当n个正方形的对角线在一条直线上时,阴影部分面积最大. 1.通过给定的xa,ya,xb,yb,可求k1,k2. 2.当n个正方形的对角线在一条直线上时,设A(x1,k1*x1),B(x2,k2*x2), 可列方程组: 解得 3.利用叉积算出AOB的面积,再减去正方形面积和的一半. #pragma comment(linker, "/STACK:102400000, 1

UVa 1643 Angle and Squares

题意: 如图,有n个正方形和一个角(均在第一象限中),使这些正方形与这个角构成封闭的阴影区域,求阴影区域面积的最大值. 分析: 直观上来看,当这n个正方形的对角线在一条直线上时,封闭区域的面积最大.(虽然我不太会证明,=_=||) 设所有正方形边长之和为L,OA.OB两直线方程分别为:y = k1x  y = k2x,设A(x1, k1x1), B(x2, k2x2),可列出方程: ,解得,相应的就得到AB两点坐标,用叉积算出△OAB的面积再减去这些正方形面积的一半就是答案. 1 #includ

UVA 11178 Morley&#39;s Theorem 计算几何

计算几何: 最基本的计算几何,差积  旋转 Morley's Theorem Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem D Morley's Theorem Input: Standard Input Output: Standard Output Morley's theorem states that that the line

uva 11796 Dog Distance (计算几何-点和直线)

C Dog Distance Input Standard Input Output Standard Output Two dogs, Ranga and Banga, are running randomly following two different paths. They both run for T seconds with different speeds. Ranga runs with a constant speed of R m/s, whereas Banga runs

uva 10652 Board Wrapping (计算几何-凸包)

Problem B Board Wrapping Input: standard input Output: standard output Time Limit: 2 seconds The small sawmill in Mission, British Columbia, has developed a brand new way of packaging boards for drying. By fixating the boards in special moulds, the b

UVA - 11437 - Triangle Fun (计算几何~)

UVA - 11437 Triangle Fun Time Limit: 1000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem A Triangle Fun Input: Standard Input Output: Standard Output In the picture below you can see a triangle ABC. Point D, E

UVA - 11796 - Dog Distance (计算几何~)

不得不感叹,计算几何真是太美丽了!! AC代码: #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <cmath> using namespace std; struct Point { double x, y; Point(double x = 0, double y = 0) : x(x) , y(y) { } }; t

poj3347 Kadj Squares (计算几何)

D - Kadj Squares Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description In this problem, you are given a sequence S1, S2, ..., Sn of squares of different sizes. The sides of the squares are integer numb

UVA - 11646 - Athletics Track (计算几何~)

题目地址:点这里 思路:计算几何入门题,首先,两个圆弧是同一个圆的,所以这个圆是矩形的外接圆,那么矩形中心就是圆心,由长宽算出角度和半径(这时用单位长度表示),再算出一个单位长度的实际长度,从而得出长和宽 AC代码: #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <cmath> using namespace std;