UVa 356-square pegs and Round Holes

Source: Internet
Author: User

Title: Draw a circle with a diameter of 2n-1 in the middle of a 2n*2n grid, asking the inner lattice of the circle and the number of squares that intersect the circle.

Analysis: Calculate geometry. The intersection point (Xi,yi) is calculated and divided by the horizontal axis of each integer.

Ceil (Yi)-ceil (yi-1) is the number of intersecting squares per column, and floor (Yi) is the number of squares in each column.

Description: Note accuracy (⊙_⊙).

#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < Cstdio> #include <cmath>using namespace Std;int main () {int n,in,on,count = 0;while (cin >> N) {in = 0,on = 0 ;d ouble r,l = n-0.5;for (int i = 1; i < n; + + i) {r = sqrt ((n-0.5) * (n-0.5)-i*i); on + = ((int) (L+1-1E-12)-(int) (r+1-1 e-12) +1) <<2;in + = ((int) (r+1e-12)) <<2;l = R;} on + = ((int) (L+1-1E-10)) <<2;if (count + +) printf ("\ n");p rintf ("in the case n =%d,%d cells contain segments of the Circle.\n ", N,on);p rintf (" There is%d cells completely contained in the circle.\n ", in);}    return 0;}


UVa 356-square pegs and Round Holes

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.