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

Hint


思路:一个圆的大小是确定的,那么就将圆心放到原点,此时只需求第一象限的方块个数,然后乘4就行了
一开始最容易想到的是直接算方块左下角到原点的距离算出来,然后判断是否比半径小就ok了
#include<stdio.h>
#include<iostream>
using namespace std;
typedef long long ll;
int main()
{
ll x, r, y;
ll dis,num;
while (~scanf("%lld%lld%lld", &x, &y, &r))
{
if (!x&&!y&&!r)
break;
ll R = r;
num = 0;
for (r; r - 1 >= 0; r--)
{
for (ll j = 0; j < R; j++)
{
dis = j*j + (r - 1)*(r - 1);
if (dis <= R*R)
num++;
if (dis == R*R&&r - 1 >= 0)
num--;
}
}
printf("%lld\n", 4 * num);
}
return 0;
}
/**********************************************************************
Problem: 1011
User: leo6033
Language: C++
Result: TLE
**********************************************************************/

很快就敲好了,结果一交,TLE

后来仔细,观察了下,发现直接算对应横坐标的高度然后除一想上取整就ok了。

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long ll;
int main()
{
ll x, r, y;
ll num;
while (~scanf("%lld%lld%lld", &x, &y, &r))
{
if (!x&&!y&&!r)
break;
num = 0;
for (ll i = 0; i < r; i++)
{
num += (ll)ceil(sqrt((double)((r*r) - (i*i))));
}
printf("%lld\n", 4 * num);
}
return 0;
}
/**********************************************************************
Problem: 1011
User: leo6033
Language: C++
Result: AC
Time:120 ms
Memory:2036 kb
**********************************************************************/

最新文章

  1. tab使用 TabActivity TabHost Tabspec常用方法
  2. 移动平台自动化测试从零开始-MonkeyRunner工具使用 (第二节)
  3. python定时器爬取豆瓣音乐Top榜歌名
  4. Struts2 设置--Myelipse
  5. MySql学习笔记(一) —— 关键字的使用
  6. python之高阶函数和匿名函数
  7. seckill(1)秒杀系统主要步骤
  8. 005_tcp/ip监控
  9. 搭建ssh框架项目(三)
  10. js arrayBuffer 字节序问题,小端法,大端法
  11. Minikube 安装
  12. postgresql数据库用户名密码验证失败
  13. Heroku第三方服务接入指南(二)
  14. java.io.ByteArrayOutputStream 源码分析
  15. word2vec相关资源
  16. 理解RESTFul和SOA
  17. poj3268 Silver Cow Party(农场派对)
  18. 关于ARM的内核架构
  19. 《转》深入理解Activity启动流程(三)–Activity启动的详细流程2
  20. NHibernate 设置主键不自增长

热门文章

  1. bootstrap-tooltip+validate
  2. 20155217 2016-2017-2 《Java程序设计》第4周学习总结
  3. Multidimensional Queries(二进制枚举+线段树+Educational Codeforces Round 56 (Rated for Div. 2))
  4. 键盘ASCII码
  5. [转]CNN 中千奇百怪的卷积方式大汇总
  6. 【原创】Linux环境下的图形系统和AMD R600显卡编程(1)——Linux环境下的图形系统简介
  7. OpenJ_POJ 1058 Guideposts
  8. [转]关于MyEclipse下的项目无法使用BASE64Encoder问题的解决办法
  9. Java数据类型以及变量的定义
  10. python网络编程-同步IO和异步IO,阻塞IO和非阻塞IO