Description

JYY has placed N bombs on the plane. We assume that the firepower area of each bomb is circle whose radius is one unit. Can you tell JYY the total firepower overlay area, just have a try ^_^

Input

Standard input will contain multiple test cases. For each test case, the first line is an integer N(N <= 100), which is the total number of the bombs. Then N lines followed and each line contains two integers X and Y, which means the 2-D coordinate of each bomb.

Output

For each test cases, output the  total firepower overlay area(accurate to two fractional digits) in one line.

Sample Input

31 11 22 2

Sample Output

6.84

​解题思路:1.首先想直接将N个圆的面积N*π,再减去相交的部分,由于A∪B∪C=A+B+C-A∩B-A∩C-B∩C+A∩B∩C比较麻烦。要记住所有相交的位置,所以本题采用相加的策略。

2.相加:分析每个圆会占据4个正方形的位置,则记录四个正方形的形状,共九种状态:如下依次为123456789:

​​然后1/2/3/4对应的面积为π/4,

5/6/7/8对应的面积为π/6+sin(π/3)/2

9的面积为1

则粘贴代码如下:

#include

#include

#include

#define Pi 3.1415926

typedef struct square{

int x;

int y;

int t;

struct square * next;

}square;

square * search(int x, int y, square * head, int type){

square * cur = head;

int flag = 0;

while (cur->next != NULL){

cur = cur->next;

if ((x == cur->x) && (y == cur->y)){

flag = 1;

if (type == 1){

if (cur->t == 1) cur->t = 1;

else if (cur->t == 2 || cur->t == 5) cur->t = 5;

else if (cur->t == 3 || cur->t == 6) cur->t = 6;

else if (cur->t == 4 || cur->t == 7 || cur->t == 8 || cur->t == 9) cur->t = 9;

break;

}

else if (type == 2){

if (cur->t == 1 || cur->t == 5) cur->t = 5;

else if (cur->t == 2) cur->t = 2;

else if (cur->t == 3 || cur->t == 6 || cur->t == 8 || cur->t == 9) cur->t = 9;

else if (cur->t == 4 || cur->t == 7)cur->t = 7;

break;

}

else if (type == 3){

if (cur->t == 1 || cur->t == 6) cur->t = 6;

else if (cur->t == 2 || cur->t == 7 || cur->t == 5 || cur->t == 9) cur->t = 9;

else if (cur->t == 3) cur->t = 3;

else if (cur->t == 4 || cur->t == 8) cur->t = 8;

break;

}

else if (type == 4){

if (cur->t == 1 || cur->t == 5 || cur->t == 6 || cur->t == 9) cur->t = 9;

else if (cur->t == 2 || cur->t == 7) cur->t = 7;

else if (cur->t == 3 || cur->t == 8) cur->t = 8;

else if (cur->t == 4) cur->t = 4;

break;

}

}

}

if ((cur->next == NULL) && (flag == 0)){

square * temp = malloc(sizeof(square));

temp->next = NULL;

temp->x = x;

temp->y = y;

temp->t = type;

cur->next = temp;

}

return head;

}

double cal(square * head){

double ans = 0;

square * pres = head;

while (pres->next != NULL){

pres = pres->next;

if ((pres->t >= 1) && (pres->t <= 4)){

ans += Pi / 4.0;

}

else if ((pres->t >= 5) && (pres->t <= 8)){

ans += Pi / 6.0 + ((double)sin(Pi / 3.0)) / 2.0;

}

else if (pres->t == 9){

ans += 1;

}

}

return ans;

}

int main(){

int N;

int i;

int x, y;

square * head = malloc(sizeof(square));

//printf("%lf", ((double)sin(Pi / 3.0)) / 2.0);

head->next = NULL;

while (scanf_s("%d", &N) != EOF){

double res = 0;

for (i = 0; i < N; i++){

scanf_s("%d %d", &x, &y);

res = cal(head);

search(x - 1, y - 1, head, 1);

search(x, y - 1, head, 2);

search(x - 1, y, head, 3);

search(x, y, head, 4);

square * temp = head;

square * cut = temp;

while (temp->next != NULL){

printf("x=%d,y=%d,type=%d\n", temp->next->x, temp->next->y, temp->next->t);

temp = temp->next;

}

}

res = cal(head);

printf("res=%.2f", res);

square * temp = head;

square * cut = temp;

while (temp->next != NULL){

cut = temp->next;

free(temp);

temp = cut;

}

}

system("pause");

}

WOJ-1097的更多相关文章

  1. WOJ -1204

    WOJ -1204 1 出现次数大于一半 那么就利用普通的堆栈的思想,如果删除两个不同的元素,原来的多数元素还是多数元素,所以采取按条件入栈的方法,如果和top元素相同则入栈,否则top--,此元素也 ...

  2. zoj 1097 普吕弗序列

    题目大意:输入一颗无根树的括号序列,求这棵树的普吕弗序列. 分析思路: 1)普吕弗序列,可以参考维基百科,其做法是找出树中编号最小的叶子节点,并将此叶子节点及边删除,并输出其邻接的节点标号: 2)递归 ...

  3. 【BZOJ】1097: [POI2007]旅游景点atr(spfa+状压dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1097 首先还是我很sb....想到了分层图想不到怎么串起来,,,以为用拓扑序搞转移,,后来感到不行. ...

  4. [swustoj 1097] 2014

    2014(1097) 问题描述 今年是2014年,所以小明喜欢2014的每一位数字(即:2,0,1,4),小明想知道在区间[l,r](包括l和r)中有多少个数中含有这4个数字(数字无前缀零). 输入 ...

  5. BZOJ 1097: [POI2007]旅游景点atr( 最短路 + 状压dp )

    先最短路预处理, 然后状压就行了 -------------------------------------------------------------------------- #include ...

  6. [Swust OJ 1097]--2014(数位dp)

    题目链接:http://acm.swust.edu.cn/problem/1097/ Time limit(ms): 1000 Memory limit(kb): 32768   今年是2014年,所 ...

  7. hdu 1097 A hard puzzle 快速幂取模

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1097 分析:简单题,快速幂取模, 由于只要求输出最后一位,所以开始就可以直接mod10. /*A ha ...

  8. PAT 1097 Deduplication on a Linked List[比较]

    1097 Deduplication on a Linked List(25 分) Given a singly linked list L with integer keys, you are su ...

  9. LightOJ 1097 - Lucky Number 线段树

    http://www.lightoj.com/volume_showproblem.php?problem=1097 题意:一个自然数序列,先去掉所有偶数项,在此基础上的序列的第二项为3,则删去所有3 ...

  10. HihoCoder 1097 Prim算法

    1097 : 最小生成树一·Prim算法 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 最近,小Hi很喜欢玩的一款游戏模拟城市开放出了新Mod,在这个Mod中,玩家可以 ...

随机推荐

  1. 在mysql数据库原有字段后增加新内容

    update table set user=concat(user,$user) where xx=xxx; [注释]这个语法要求原来的字段值不能为null(可以为空字符''):

  2. [渣译文] 使用 MVC 5 的 EF6 Code First 入门 系列:为ASP.NET MVC应用程序更新相关数据

    这是微软官方教程Getting Started with Entity Framework 6 Code First using MVC 5 系列的翻译,这里是第八篇:为ASP.NET MVC应用程序 ...

  3. C#中的多线程 - 基础知识

    原文:http://www.albahari.com/threading/ 文章来源:http://blog.gkarch.com/threading/part1.html 1简介及概念 C# 支持通 ...

  4. jquery引用方法时传递参数

    经常到网上去下载大牛们写的js插件.每次只需将js引用并设置下变量就行了,但一直没搞明白原理(主要是大牛们的代码太简练了-,-). 这次弄清了如何传递.设置多个(很多个)参数. 如 方法为functi ...

  5. 内部类 & 泛型

    内部类 主要作用 1. 内部类, 主要用于事件监听的方法实现.2. 用于多继承 注: 主要还是 1 用的比较多. 参考 : head first java (第12章) 泛型 head first j ...

  6. GitHub下载的 Git Shell中出现的字符支持警告,将字体修改为新宋体即可

    ——解决办法: 将命令行字体修改为新宋体就可以了. 文章引用:http://www.cnblogs.com/veryinf/archive/2012/10/26/2740899.html

  7. TCP/IP协议学习(二) LWIP用户自定义配置文件解析

    LWIP协议支持用户配置,可以通过用户裁剪实现最优化配置,LWIP默认包含opts.h作为系统默认配置,不过通过添加lwipopts.h文件并包含在opts.h头文件之前就可以对lwip进行用户裁剪, ...

  8. Linux 磁盘管理

    Linux磁盘管理好坏管理直接关系到整个系统的性能问题. Linux磁盘管理常用三个命令为df.du和fdisk. df:列出文件系统的整体磁盘使用量 du:检查磁盘空间使用量 fdisk:用于磁盘分 ...

  9. quartz-2.2.x 快速入门 (1)

    欢迎来到quartz快速入门教程.阅读本教程,你将会了解: quartz下载 quartz安装 根据你的需要,配置Quartz 开始一个示例应用   当熟悉了quratz调度的基本功能后,可以尝试一些 ...

  10. 算法课堂笔记13—Online Algorithm

    今天的算法课是学习离线算法,在计算机科学中,一个在线算法是指它可以以序列化的方式一个个的处理输入,也就是说在开始时并不需要已经知道所有的输入.相对的,对于一个离线算法,在开始时就需要知道问题的所有输入 ...