Description

Did you know that if you draw a circle that fills the screen on your 1080p high definition display, almost a million pixels are lit? That's a lot of pixels! But do you know exactly how many pixels are lit? Let's find out!

Assume that our display is set on a Cartesian grid where every pixel is a perfect unit square. For example, one pixel occupies the area of a square with corners (0,0) and (1,1). A circle can be drawn by specifying its center in grid coordinates and its radius. On our display, a pixel is lit if any part of it is covered by the circle being drawn; pixels whose edge or corner are just touched by the circle, however, are not lit.

Your job is to compute the exact number of pixels that are lit when a circle with a given position and radius is drawn.

Input

The input consists of several test cases, each on a separate line. Each test case consists of three integers, x,y, and r(1≤x,y,r≤1,000,000), specifying respectively the center (x,y) and radius of the circle drawn. Input is followed by a single line with x = y = r = 0, which should not be processed.

Output

For each test case, output on a single line the number of pixels that are lit when the specified circle is drawn. Assume that the entire circle will fit within the area of the display.

Sample Input

1 1 1
5 2 5
0 0 0

Sample Output

4
88 题意:给定圆心和半径,要你找这个圆覆盖了多少的矩形。由于圆是中心对称,所以考虑四分之一的圆。
那么怎么想?考虑右上方的四分之圆,如果一个一个矩形被覆盖,那么这个矩形的左下角的点到圆心的距离一定小于半径,可以自己画下图理解,如果这个矩形在圆内,那么这个矩形以下的一列都会被圆覆盖,所以我们考虑离圆心最远
的每个矩形,不断的向右向下走,直到它运动到圆心的水平线下。最后乘以4就是答案,不懂可以看代码和画图理解一下,应该不难。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;
const int maxn=1005;
typedef long long LL;
int x,y,r;
int main()
{
while(scanf("%d %d %d",&x,&y,&r)!=EOF)
{
if(x==0&&y==0&&r==0)
return 0;
else
{
LL ans=0;
int i=r-1,j=0;
LL temp=r*r;
while(j<r)
{
if(i*i+j*j<temp)
ans+=(i+1);
else
{
i--;
continue;
}
j++;
}
printf("%lld\n",ans*4);
}
}
return 0;
} /**********************************************************************
Problem: 1011
User: therang
Language: C++
Result: AC
Time:28 ms
Memory:2024 kb
**********************************************************************/

  

最新文章

  1. pagerank
  2. [Android Pro] Normal Permissions
  3. 精确计算TFS中新增以及更改的代码行数
  4. NOIP200003方格取数
  5. 此博客记录我的进阶之路(PHP、C、Python、Erlang)
  6. C++的类和对象
  7. LeetCode之Maximum Product Subarray
  8. cura-engine学习(3)
  9. 20. Valid Parentheses【leetcode】
  10. 如何在Win7安装U盘中加入USB3.0驱动的支持
  11. VMware Workstation 10序列号:
  12. 集合List的排序
  13. jmeter测试mysql遇到的问题
  14. NOIP复习篇
  15. LeeCX - 开源后台管理系统简单介绍
  16. 如何清除浮动塌陷? float:left 塌陷
  17. 【062有新题】OCP 12c 062出现大量之前没有的新考题-16
  18. SpringBoot整合Swagger-ui
  19. C#或者.NET下的强制垃圾回收办法
  20. JavaScript 开闭原则OCP

热门文章

  1. Extjs 4 MVC中全局配置文件
  2. eclipse集成lombok注解不起作用
  3. bzoj 3029: 守卫者的挑战【概率dp】
  4. 洛谷 P4015 运输问题 【最小费用最大流+最大费用最大流】
  5. css实现侧边展开收起
  6. python的安装教学
  7. 升级Python后, yum不能用了
  8. 利用爬虫将Yuan先生的博客文章爬取下来
  9. 前端基础jQuery
  10. 图论/暴力 Codeforces Beta Round #94 (Div. 2 Only) B. Students and Shoelaces