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
**********************************************************************/

  

CSU1011: Counting Pixels的更多相关文章

  1. CSUOJ 1011 Counting Pixels

    Description Did you know that if you draw a circle that fills the screen on your 1080p high definiti ...

  2. 萌新笔记——Cardinality Estimation算法学习(二)(Linear Counting算法、最大似然估计(MLE))

    在上篇,我了解了基数的基本概念,现在进入Linear Counting算法的学习. 理解颇浅,还请大神指点! http://blog.codinglabs.org/articles/algorithm ...

  3. POJ_2386 Lake Counting (dfs 错了一个负号找了一上午)

    来之不易的2017第一发ac http://poj.org/problem?id=2386 Lake Counting Time Limit: 1000MS   Memory Limit: 65536 ...

  4. [LeetCode] Smallest Rectangle Enclosing Black Pixels 包含黑像素的最小矩阵

    An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The black ...

  5. ZOJ3944 People Counting ZOJ3939 The Lucky Week (模拟)

    ZOJ3944 People Counting ZOJ3939 The Lucky Week 1.PeopleConting 题意:照片上有很多个人,用矩阵里的字符表示.一个人如下: .O. /|\ ...

  6. find out the neighbouring max D_value by counting sort in stack

    #include <stdio.h> #include <malloc.h> #define MAX_STACK 10 ; // define the node of stac ...

  7. 1004. Counting Leaves (30)

    1004. Counting Leaves (30)   A family hierarchy is usually presented by a pedigree tree. Your job is ...

  8. 6.Counting Point Mutations

    Problem Figure 2. The Hamming distance between these two strings is 7. Mismatched symbols are colore ...

  9. 1.Counting DNA Nucleotides

    Problem A string is simply an ordered collection of symbols selected from some alphabet and formed i ...

随机推荐

  1. 解决weblogic页面和控制台乱码问题

    转自:https://blog.csdn.net/u010995831/article/details/53283746 之前一直有碰到weblogic各种乱码问题,要不就是页面乱码,要不就是控制台乱 ...

  2. RocketMQ消费者实践

    最近工作中用到了RocketMQ,现记录下,如何正确实现消费~ 消费者需要注意的问题 防止重复消费 如何快速消费 消费失败如何处理 Consumer具体实现 防止重复消费 重复消费会造成数据不一致等问 ...

  3. SS上网配置(Window 7/8/10 )详解

    SS很多人都会用到,尤其是做外贸的朋友,今天我们来说下SS相关的配置. 首先从官网下载解压后的目录如结构下: ​ 点击***.exe,选择以管理员身份运行,切记打开后界面如下 ​​ 服务器地址为一段I ...

  4. Luogu P3916 图的遍历 【优雅的dfs】【内有待填坑】By cellur925

    说明 • 对于60% 的数据, n,m在1e3内 • 对于100% 的数据, n,m在1e5内. 本弱弱上来就是一顿暴搜打,dfs n次,每次更新答案,复杂度为O(n*n),果然TLE,60分抱回家. ...

  5. 8. VIM 系列 - 利用 VIM 8.1 版本编译项目和GDB调试

    目录 term 模式 termdebug 模式 VIM版本安装请参考: 0. VIM 系列 - 源码升级最新版本vim term 模式 输入:term 打开此模式,效果如下 这个模式有编辑文本窗口和s ...

  6. 使用python计算softmax函数

    softmax计算公式:                        Softmax是机器学习中一个非常重要的工具,他可以兼容 logistics 算法.可以独立作为机器学习的模型进行建模训练.还可 ...

  7. 扩展KMP的应用

    扩展KMP的应用: 给出模板串S和串T,长度分别为Slen和Tlen,要求在线性时间内,对于每个S[i](0<=i<Slen),求出S[i..Slen-1]与T的 最长公共前缀长度,记为e ...

  8. matlab实现算术编解码 分类: 图像处理 2014-06-01 23:01 357人阅读 评论(0) 收藏

    利用Matlab实现算术编解码过程,程序如下: clc,clear all; symbol=['abc']; pr=[0.4 0.4 0.2]; %各字符出现的概率 temp=[0.0 0.4 0.8 ...

  9. Android偏好设置(7)自定义Preference,和PreferenceDialog

    Building a Custom Preference The Android framework includes a variety of Preference subclasses that ...

  10. Access OLE对象和附件的区别

    OLE 对象 来自 Office 和基于 Windows 的程序的图像.文档.图形和其他对象 最多可存储 2GB 数据(此大小限制适用于所有 Access 数据库).请记住,添加 2GB 数据会导致数 ...