题目:在一个2n*2n的网格中间画一个直径为2n-1的圆,问圆内部的格子以及和圆相交的格子个数。

思路:只要考虑1 / 4圆的点就行,用点到原点距离与半径比较,当格子左下方和右上方都在格子里时,格子在圆内部。

AC代码:

 #include<bits/stdc++.h>
using namespace std;
int sqr(int n, int m)
{
return m * m + n * n;
}
int main()
{
int n;
int cnt = ;
while(cin >> n)
{
if(cnt++) cout << endl;
double r = (n - 0.5) *(n - 0.5);
int in = ;
int side = ;
for(int i = ;i < n;i++)
{
for(int j = ;j < n;j++)
{
if(sqr(i , j) < r && sqr(i + , j + ) < r ) in ++;
else if(sqr(i , j) < r && sqr(i + , j + ) > r) side++;
}
}
printf("In the case n = %d, %d cells contain segments of the circle.\n",n,side*);
printf("There are %d cells completely contained in the circle.\n",in*);
}
return ;
}

UVA 356 - Square Pegs And Round Holes的更多相关文章

  1. UVA 11542 - Square(高斯消元)

    UVA 11542 - Square 题目链接 题意:给定一些数字.保证这些数字质因子不会超过500,求这些数字中选出几个,乘积为全然平方数,问有几种选法 思路:对每一个数字分解成质因子后.发现假设要 ...

  2. uva 3523 Knights of the Round Table

    题意:给你n,m n为有多少人,m为有多少组关系,每组关系代表两人相互憎恨,问有多少个骑士不能参加任何一个会议. 白书算法指南 对于每个双联通分量,若不是二分图,就把里面的节点标记 #include ...

  3. UVA 1364 - Knights of the Round Table (获得双连接组件 + 二部图推理染色)

    尤其是不要谈了些什么,我想A这个问题! FML啊.....! 题意来自 kuangbin: 亚瑟王要在圆桌上召开骑士会议.为了不引发骑士之间的冲突. 而且可以让会议的议题有令人惬意的结果,每次开会前都 ...

  4. UVa 11461 - Square Numbers【数学,暴力】

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  5. UVA 11461 - Square Numbers 数学水题

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  6. C Make a Square Educational Codeforces Round 42 (Rated for Div. 2) (暴力枚举,字符串匹配)

    C. Make a Square time limit per test2 seconds memory limit per test256 megabytes inputstandard input ...

  7. xor方程组消元 UVA 11542 Square

    题目传送门 题意:给n个数,选择一些数字乘积为平方数的选择方案数.训练指南题目. 分析:每一个数字分解质因数.比如4, 6, 10, 15,, , , , 令,表示选择第i个数字,那么,如果p是平方数 ...

  8. UVA 11461 - Square Numbers(水题)

    题目链接 #include <cstdio> #include <cstring> #include <string> #include <cmath> ...

  9. UVA 11461 - Square Numbers

    题目:统计区间中的平方数个数. 分析: ... #include <stdio.h> #include <string.h> ]; int main() { int i, a, ...

随机推荐

  1. 54、salesforce学习笔记(一)

    Decimal priceDecimal = -4.50; System.debug('小数的绝对值为:'+priceDecimal.abs()); System.debug('priceDecima ...

  2. 用 Flask 来写个轻博客 (15) — M(V)C_实现博文页面评论表单

    目录 目录 前文列表 实现 post 视图函数 在 posthtml 中添加表单 效果 前文列表 用 Flask 来写个轻博客 (1) - 创建项目 用 Flask 来写个轻博客 (2) - Hell ...

  3. 大数据学习之BigData常用算法和数据结构

    大数据学习之BigData常用算法和数据结构 1.Bloom Filter     由一个很长的二进制向量和一系列hash函数组成     优点:可以减少IO操作,省空间     缺点:不支持删除,有 ...

  4. 更改package.js后重新加载

    node --save可有省略掉手动修改package.json的步骤   当你为你的模块安装一个依赖模块时,正常情况下你得先安装他们(在模块根目录下npm install module-name), ...

  5. camunda授权的一些简单操作

    /** * 授权操作 */public class ZccAuthorizationService { AuthorizationService authorizationService; @Befo ...

  6. Python升级3.多

    本文主要介绍在Linux(CentOS)下将Python的版本升级为3.6.2的方法 众所周知,在2020年python官方将不再支持2.7版本的python,所以使用3.x版本的python是必要的 ...

  7. 28-python基础-python3-列表多重赋值

    1-列表多重赋值常规方法 >>> cat = ['fat', 'black', 'loud'] >>> size = cat[0] >>> col ...

  8. 【Spring】每个程序员都使用Spring(四)——Aop+自定义注解做日志拦截

    一.前言 上一篇博客向大家介绍了Aop的概念,对切面=切点+通知 .连接点.织入.目标对象.代理(jdk动态代理和CGLIB代理)有所了解了.理论很强,实用就在这篇博客介绍. 这篇博客中,小编向大家介 ...

  9. 隐式激活Activity

  10. 使用SQLiteOpenHelper管理SD卡中的数据库

    本人在网上找了好多大牛的资料,研究了几天终于调试出来了.以下是笔记: SQLiteOpenHelper是Android框架为我们提供的一个非常好的数据库打开.升级与关闭的工具类.但是这个工具类会自动把 ...