uva 12121 - You are around me ...(贪心+几何)
2014-03-27 23:26
459 查看
题目链接:uva 12121 - You are around me ...
题目大意:给出n,e和th,表示有n个男孩,每个男孩有一个椭圆形的区间,离心率为e,和x轴的坐标夹角为th,没个男孩的区间大小都相同,并且没有两个男孩的区间重叠,问说椭圆形的面积最大为多少。
解题思路:将整个坐标系旋转反的th角度,然后将每个点按照x排序,遍历一遍,根据e和两点坐标求出a,维护a的最小值。然后再按照y同样做一次即可。
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
const int N = 15005;
const double pi = 4.0 * atan(1.0);
const double INF = 0x3f3f3f3f3f3f3f3f;
struct point {
double x, y;
}p
;
int n;
double e, th, k;
inline void init () {
double xi, yi;
th = th * pi / 180;
for (int i = 0; i < n; i++) {
scanf("%lf%lf", &xi, &yi);
p[i].x = xi * cos(th) + yi * sin(th);
p[i].y = -xi * sin(th) + yi * cos(th);
}
}
inline bool cmpX (const point& a, const point& b) {
return a.x < b.x;
}
inline bool cmpY (const point& a, const point& b) {
return a.y < b.y;
}
inline double cat (point a, point b) {
double xi = fabs(a.x - b.x) / 2;
double yi = fabs(a.y - b.y) / 2;
return (k * xi * xi + yi * yi) / k;
}
double solve () {
double ans = INF;
sort (p, p + n, cmpX);
for (int t = 0; t < 2; t++) {
for (int i = 1; i < n; i++) {
double tmp = cat(p[i-1], p[i]);
ans = min (ans, tmp);
}
sort (p, p + n, cmpY);
}
return ans;
}
int main () {
int cas = 1;
while (scanf("%d%lf%lf", &n, &e, &th) == 3 && n && e && th) {
init ();
k = 1 - e * e;
double d = solve ();
printf("Case %d:\n", cas++);
if (e == 1)
printf("%.6lf\n", 0.0);
else
printf("%.6lf\n", pi * d * sqrt(k));
}
return 0;
}
题目大意:给出n,e和th,表示有n个男孩,每个男孩有一个椭圆形的区间,离心率为e,和x轴的坐标夹角为th,没个男孩的区间大小都相同,并且没有两个男孩的区间重叠,问说椭圆形的面积最大为多少。
解题思路:将整个坐标系旋转反的th角度,然后将每个点按照x排序,遍历一遍,根据e和两点坐标求出a,维护a的最小值。然后再按照y同样做一次即可。
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
const int N = 15005;
const double pi = 4.0 * atan(1.0);
const double INF = 0x3f3f3f3f3f3f3f3f;
struct point {
double x, y;
}p
;
int n;
double e, th, k;
inline void init () {
double xi, yi;
th = th * pi / 180;
for (int i = 0; i < n; i++) {
scanf("%lf%lf", &xi, &yi);
p[i].x = xi * cos(th) + yi * sin(th);
p[i].y = -xi * sin(th) + yi * cos(th);
}
}
inline bool cmpX (const point& a, const point& b) {
return a.x < b.x;
}
inline bool cmpY (const point& a, const point& b) {
return a.y < b.y;
}
inline double cat (point a, point b) {
double xi = fabs(a.x - b.x) / 2;
double yi = fabs(a.y - b.y) / 2;
return (k * xi * xi + yi * yi) / k;
}
double solve () {
double ans = INF;
sort (p, p + n, cmpX);
for (int t = 0; t < 2; t++) {
for (int i = 1; i < n; i++) {
double tmp = cat(p[i-1], p[i]);
ans = min (ans, tmp);
}
sort (p, p + n, cmpY);
}
return ans;
}
int main () {
int cas = 1;
while (scanf("%d%lf%lf", &n, &e, &th) == 3 && n && e && th) {
init ();
k = 1 - e * e;
double d = solve ();
printf("Case %d:\n", cas++);
if (e == 1)
printf("%.6lf\n", 0.0);
else
printf("%.6lf\n", pi * d * sqrt(k));
}
return 0;
}
相关文章推荐
- UVA 12121 - You are around me ...(贪心+几何)
- UVALive - 4062 You are around me ...
- uva 1373 - How I Wonder What You Are!(几何)
- Python!Are you kidding me?
- Xcode 提交代码到github 报 Please tell me who you are
- xcode7 弹出 please tell me who you are
- uva 1531 & poj 1518 Problem Bee(几何计算+贪心)
- *** Please tell me who you are.
- git---commit 操作遇到提交失败,tell me who you are
- 新建工程出现 ***Please tell me who you are 解决办法
- git Please tell me who you are解决方法
- Xcode中git的使用方法介绍与"Please tell me who you are"问题的解决方案
- You are not working for me....................
- Integer.getInteger,are you kinding me? 好吧, 我还是没怎么弄明白,求高人解答。。。
- Git: “please tell me who you are”
- git提示please tell me who you are
- POJ1518、 UVA1531 - Problem Bee(几何+贪心)
- ***please tell me who you are
- xcode 弹出 please tell me who you are
- Why are you so special to me