题目:在一个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. IOS 基于APNS消息推(JAVA后台)

    直接上Demo import java.util.ArrayList; import java.util.List; import org.apache.commons.lang3.StringUti ...

  2. HTML-参考手册: HTML 字符集

    ylbtech-HTML-参考手册: HTML 字符集 1.返回顶部 1. HTML 字符集 HTML 字符集 如需正确地显示 HTML 页面,浏览器必须知道使用何种字符集. 万维网早期使用的字符集是 ...

  3. 用FastDFS一步步搭建图片服务器(单机版)

    一.FastDFS介绍 FastDFS开源地址:https://github.com/happyfish100 参考:分布式文件系统FastDFS设计原理 参考:FastDFS分布式文件系统 1.简介 ...

  4. Linux随笔 - DNS搭建

    域名系统(英文:Domain Name System,缩写:DNS)是因特网的一项服务.它作为将域名和IP地址相互映射的一个分布式数据库,能够使人更方便的访问互联网.DNS 使用TCP和UDP端口53 ...

  5. 模板引擎的简单原理template

    ​ var templateStr = "我的名字叫<%=name%>我是一只小狗,今年<%=age%>岁."; var data = { name:'旺财 ...

  6. 3. Node_export安装部署

    首先我们要知道什么是Node_export?因为Prometheus本身不具备监控功能,我们要通过Prometheus收集数据,需要安装对应的export.如Node_export用于监控服务器状态, ...

  7. 微信小程序观察者模式 observers

    const app = getApp(); const request = require('../../../utils/request.js'); Component({ options: { m ...

  8. Git操作思维导图

    转自:https://blog.csdn.net/mynameishuangshuai/article/details/51657324

  9. 从输入url到显示网页,发生了那些事情?

    作为一个软件开发者,你一定会对网络应用如何工作有一个完整的层次化的认知,同样这里也包括这些应用所用到的技术:像浏览器,HTTP,HTML,网络服务器,需求处理等等. 本文将更深入的研究当你输入一个网址 ...

  10. change transformation file in PI interface

    1. Jane extends the ZTMMASKU sap table 2. Jane write the program to write the new attribute to the t ...