CSU1011: Counting Pixels
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的更多相关文章
- CSUOJ 1011 Counting Pixels
Description Did you know that if you draw a circle that fills the screen on your 1080p high definiti ...
- 萌新笔记——Cardinality Estimation算法学习(二)(Linear Counting算法、最大似然估计(MLE))
在上篇,我了解了基数的基本概念,现在进入Linear Counting算法的学习. 理解颇浅,还请大神指点! http://blog.codinglabs.org/articles/algorithm ...
- POJ_2386 Lake Counting (dfs 错了一个负号找了一上午)
来之不易的2017第一发ac http://poj.org/problem?id=2386 Lake Counting Time Limit: 1000MS Memory Limit: 65536 ...
- [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 ...
- ZOJ3944 People Counting ZOJ3939 The Lucky Week (模拟)
ZOJ3944 People Counting ZOJ3939 The Lucky Week 1.PeopleConting 题意:照片上有很多个人,用矩阵里的字符表示.一个人如下: .O. /|\ ...
- 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 ...
- 1004. Counting Leaves (30)
1004. Counting Leaves (30) A family hierarchy is usually presented by a pedigree tree. Your job is ...
- 6.Counting Point Mutations
Problem Figure 2. The Hamming distance between these two strings is 7. Mismatched symbols are colore ...
- 1.Counting DNA Nucleotides
Problem A string is simply an ordered collection of symbols selected from some alphabet and formed i ...
随机推荐
- asp.net mvc4 controller
controller返回几种返回结果
- Spring IOC 一——容器装配Bean的简单使用
下文:SpringIOC 二-- 容器 和 Bean的深入理解 写在前面 这篇文章去年写的,缘起于去年某段时间被领导临时"抓壮丁"般的叫过去做java开发,然后在网上找了一个 Sp ...
- Mac下Ruby升级与Rails的安装
也是醉了,网上查了半天一脸懵逼.然后自己动手试试 gem install rails瞬间命令行就没反应了,以为命令行挂了,但是一会儿报错说是没有权限. 好吧,那么来这个 sudo gem instal ...
- Luogu P1122最大子树和 【水树形Dp】By cellur925
题目描述 小明对数学饱有兴趣,并且是个勤奋好学的学生,总是在课后留在教室向老师请教一些问题.一天他早晨骑车去上课,路上见到一个老伯正在修剪花花草草,顿时想到了一个有关修剪花卉的问题.于是当日课后,小明 ...
- java String, StringBuffer ,StringBulider 区别
1. String 是不可变的(immutable): 创建后不能修改: 2. StringBuffer 线程安全的,可变字符串: 3. StringBuilder 线程不安全,所以性能比较高
- [Usaco2006 Jan] Dollar Dayz 奶牛商店
Description 约翰到奶牛商场里买工具.商场里有K(1≤K≤100).种工具,价格分别为1,2,-,K美元.约翰手里有N(1≤N≤1000)美元,必须花完.那他有多少种购买的组合呢? Inpu ...
- Windows7运行无法记录历史命令问题解决
Windows7运行无法记录历史命令,每次都需要手动敲命令,解决方法如下: 1.任务栏中右键,选择"属性"菜单: 2.在弹出框中的"[开始]菜单"选项卡的隐私区 ...
- html 测试
斯蒂芬斯蒂芬 20:23你过来吧,我们好好谈一谈 好好学习 21:22这是一个无法避免的错误 作为一个新手,我在学习HTML文件的格式,我觉得博客园的编辑器很棒, 查看这些源代码让我学习到了许多知识. ...
- 转 SQL - 字符串中的转义字符
一位同事在使用SQL处理一串字符时,出现一个意料之外的问题:这个字符串中包括字符‘&’.我们先看一下现象: SQL> select * from v$version; B ...
- 213 House Robber II 打家劫舍 II
注意事项: 这是 打家劫舍 的延伸.在上次盗窃完一条街道之后,窃贼又转到了一个新的地方,这样他就不会引起太多注意.这一次,这个地方的所有房屋都围成一圈.这意味着第一个房子是最后一个是紧挨着的.同时,这 ...