CSUOJ 1011 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
Hint
#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
#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
**********************************************************************/
最新文章
- tab使用 TabActivity TabHost Tabspec常用方法
- 移动平台自动化测试从零开始-MonkeyRunner工具使用 (第二节)
- python定时器爬取豆瓣音乐Top榜歌名
- Struts2 设置--Myelipse
- MySql学习笔记(一) —— 关键字的使用
- python之高阶函数和匿名函数
- seckill(1)秒杀系统主要步骤
- 005_tcp/ip监控
- 搭建ssh框架项目(三)
- js arrayBuffer 字节序问题,小端法,大端法
- Minikube 安装
- postgresql数据库用户名密码验证失败
- Heroku第三方服务接入指南(二)
- java.io.ByteArrayOutputStream 源码分析
- word2vec相关资源
- 理解RESTFul和SOA
- poj3268 Silver Cow Party(农场派对)
- 关于ARM的内核架构
- 《转》深入理解Activity启动流程(三)–Activity启动的详细流程2
- NHibernate 设置主键不自增长
热门文章
- bootstrap-tooltip+validate
- 20155217 2016-2017-2 《Java程序设计》第4周学习总结
- Multidimensional Queries(二进制枚举+线段树+Educational Codeforces Round 56 (Rated for Div. 2))
- 键盘ASCII码
- [转]CNN 中千奇百怪的卷积方式大汇总
- 【原创】Linux环境下的图形系统和AMD R600显卡编程(1)——Linux环境下的图形系统简介
- OpenJ_POJ 1058 Guideposts
- [转]关于MyEclipse下的项目无法使用BASE64Encoder问题的解决办法
- Java数据类型以及变量的定义
- python网络编程-同步IO和异步IO,阻塞IO和非阻塞IO