UVALive 6741 The Sacrificial Firepits

来源:互联网 发布:apache spark hadoop 编辑:程序博客网 时间:2024/05/03 05:32
简单的几何水题,就是给出两个等边三角形的Size,用一个矩形去cover这两个三角形。求这样的矩形的最小面积。
#include <cstdio>#include <cmath>#include <algorithm>using namespace std;int main(){  int i, t;  scanf("%d", &t);  while ( t -- )  {    int s1, s2;    double ans = 0;    scanf("%d%d", &s1, &s2);    if ( s1 > s2 ) swap(s1, s2);    if ( s1 == s2 ) ans = sqrt(3) * s1 * s1 / 4 * 3;//两个等边三角形直接边对边,变成平行四边形那样    else if ( s1 * 2 <= s2 ) ans = sqrt(3) * s2 * s2 / 2;//取变长较长的作为矩形的底边    else if ( s1 * 2 > s2 ) ans = sqrt(3) * s2 / 2 * ( s1 + s2 * 0.5);        printf("%.3lf\n", ans);  }  return 0;}


0 0