UVA, 356 Square Pegs And Round Holes
来源:互联网 发布:qsv视频格式转换器mac 编辑:程序博客网 时间:2024/05/20 17:21
题目: 给一个n。构建一个2n*2n的方格。里面放一个半径为n的圆。求落在边上的和完全在内部的格子个数
注意:输出的时候。几组数之间有空行。最后一组后面没有
只需要算1/4的。由于对称性
#include <cstdio>#include <string.h>#include <cstdlib>#include <cmath>#include <ctgmath>#include <iostream>#include <vector>#include <algorithm>#include <map>using namespace std;//(0,0)到(m,n)距离的平方int func(int m,int n){ return m*m+n*n;}int main(){ //只需要考虑四分之一的区域 int n; int count = 0;//计数,方便回车输出 while (cin>>n) { int i,j; double r = (n - 0.5) * (n - 0.5);//半径的平方 // cout<<r<<endl; int neibu = 0;//内部 int bianjie = 0;//边上 //遍历所有格子的左下角 for(i=0; i<=n-1; i++){ for(j=0; j<=n-1; j++){ //左下和右上都在r内部 if( (func(i, j) < r) && (func(i+1, j+1) < r) ) neibu++; else if( (func(i, j) < r) && (func(i+1, j+1) > r)) bianjie++; } } // cout<<neibu<<endl<<bianjie; if(count++) cout<<endl; printf("In the case n = %d, %d cells contain segments of the circle.\n",n,bianjie*4); printf("There are %d cells completely contained in the circle.\n",neibu*4); } return 0;}
0 0
- UVA 356 Square Pegs And Round Holes
- UVa 356 - Square Pegs And Round Holes
- UVA, 356 Square Pegs And Round Holes
- UVA 356 || Square Pegs And Round Holes (圆能覆盖的格子数和边界穿过的格子数
- UVA 356 SquarePegs And Round Holes(点到圆心的距离)
- UVA - 1533 Moving Pegs
- UVA - 1533 (Moving Pegs)
- UVA 12569 Moving Pegs
- Moving Pegs UVA
- Codeforces Round #356 (Div. 2) Bear and Square Grid
- Codeforces Round #356 (Div. 2)E. Bear and Square Grid
- 【Codeforces797F】Mice and Holes
- uva 1533 - Moving Pegs(BFS)
- Codeforces Round #356 (Div. 2) Bear and Square Grid ★ ★ ★
- Codeforces Round #356 (Div. 2) E. Bear and Square Grid 滑块
- UVa #1533 Moving Pegs (习题7-12)
- UVA 1533 - Moving Pegs 状态压缩 + bfs
- Codeforces Round #369 (Div. 2) B. Chris and Magic Square
- QuickHit(打字游戏)项目源代码
- SOAP引擎简介
- 自定义QCheckBox以及QRadioButton
- Egret图文混排
- 蓝桥杯----角谷步数
- UVA, 356 Square Pegs And Round Holes
- Reflection in C++: The simple implementation of Splinter Cell
- 分类 & 类扩展(category / extension)
- OpenCV_连通区域分析(Connected Component Analysis/Labeling)
- Chrome下载文件错误:收到了来自服务器的重复标头
- 如何将本地的项目上传到github
- CentOS7安装zookeeper
- reverse
- BP神经网络的优缺点