7.14 question C

Source: Internet
Author: User

Link: http://code.bupt.edu.cn/problem/p/415/

Elder brother Time Limit1000 MS Memory limit65536 kb question description

Xuejie is writing her homework, but she began to want to learn her younger brother, and she began to draw circles on the paper. At this moment, the younger brother suddenly appeared. The curious younger brother asked her what she was doing. in a panic, she casually said she wanted to calculate the area covered by these circles. The younger brother immediately admired the elder sister, but the elder sister suddenly realized that she would not do it. In order to make a good impression on her younger brother, she asked you to help her calculate the covered area.
To simplify the problem, we assume that the radius of all circles is 1.

Input Format

Multiple groups of data are input. Starts with an integer. T (T ≤ 10) Indicates the number of data groups. The next T group is input. Each group starts with an integer. N (1 ≤ n ≤ 100) Indicates the number of circles drawn by xuejie. N Line, two integers in each line X I, y I Indicates the coordinates of the center of the circle, 1 ≤ x I, y I ≤ 100 .

Output Format

Output a number that represents the area and is accurate to the last five digits of the decimal point.

Input example
121 12 1
Output example
5.05482

It is generally impossible to solve this problem as junior high school and high school do. We need to think in the form of computer thinking. Because the data is less than 100, we can traverse every grid, calculates the cumulative sum by calculating the area. For each grid, there are only three situations. The other is fully covered by circles. You only need to count the number of occurrences of each grid, multiplied by the area of the image, it can be solved, it is worth noting that the traversal should (0, 0) traverse to (100,100), at that time I only traverse to (), pitfall for a long time, t_t


Code:

#include <iostream>#include <cstdio>#include <cstring>#include <cmath>using namespace std;const double pi=acos(-1.0);int cir[111][111];int main(){    double ans;    double s1=pi/4;    double s2=pi/6+sqrt(3)/4;    double s3=1.0;    int t;    scanf("%d",&t);    while(t--)    {        ans=0;        memset(cir,0,sizeof(cir));        int n;        scanf("%d",&n);        for(int i=0;i<n;i++)        {            int x,y;            scanf("%d%d",&x,&y);            cir[x][y]=1;        }        for(int i=0;i<=100;i++)            for(int j=0;j<=100;j++)            {                if(cir[i][j]+cir[i+1][j]+cir[i][j+1]+cir[i+1][j+1]==1)                    ans+=s1;                else if((cir[i][j]==1&&cir[i+1][j+1]==1)||(cir[i+1][j]==1&&cir[i][j+1]==1))                    ans+=s3;                else if(!(cir[i][j]+cir[i+1][j]+cir[i][j+1]+cir[i+1][j+1]==0))                    ans+=s2;            }        printf("%.5f\n",ans);    }    return 0;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.