您的位置:首页 > 其它

Ural_1333. Genie Bomber 2

2011-10-29 17:11 218 查看
  /*从昨晚开始想这题,看到队友有人1Y很快过了,备受打击。然后就一直考虑各种情
况,各种debug,都没能过。下午另一个队友也很快1Y了,很纳闷,问了一下,搜的解题
报告,思路是把1*1的方格分成1000*1000个离散的点,然后统计被圆覆盖的点的个数。这
个方法实在有点。。。无语。发现有的人一不会就搜解题报告,没意思,宁愿浪费时间也
不那样做,这题算是间接的看得解题报告吧。检讨!*/

//Copy thinking code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

const int N = 11;

struct circle{
double x;
double y;
double r;
}c
;

int n;

bool in_this_circle(int i, double a, double b){
double tmp = sqrt((a-c[i].x)*(a-c[i].x) + (b-c[i].y)*(b-c[i].y));
return  tmp > c[i].r ? 0 : 1;
}

bool in_circle(double i, double j){
for(int x = 0; x < n; x++)
if(in_this_circle(x, i, j))
return true;
return false;
}

int main(){
//freopen("data.in", "r", stdin);

int k, cnt;
double i, j;

scanf("%d", &n);
for(k = 0; k < n; k++)
scanf("%lf%lf%lf", &c[k].x, &c[k].y, &c[k].r);

for(cnt = 0, i = 0; i <= 1; i += 0.001)
for(j = 0; j <= 1; j += 0.001)
if(in_circle(i, j))
cnt++;

printf("%lf\n", double(cnt)/(1000*1000)*100);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: