HLJUOJ1122(暴力枚举)
来源:互联网 发布:淘宝有没有卖透视眼镜 编辑:程序博客网 时间:2024/05/16 09:02
无以伦比的圆
Time Limit: 1 Sec Memory Limit:128 MB
Submit: 19 Solved: 8
[Submit][Status][Web Board]
Submit: 19 Solved: 8
[Submit][Status][Web Board]
Description
1×1的格子长宽各等分50份,形成2500个单位格子,给出n个圆,覆盖单位小格子,求没有被覆盖的格子的个数。一个格子被覆盖,是它的中心在圆内。
Input
多组测试样例,读到文件末尾
每组样例第一行两个个数n、r,代表圆的个数和每个圆的半径
接下来n行,每行两个数x、y,代表每个圆的坐标。
0<x、y、r<1
n<=100
Output
每组数据输出一个数,代表这些圆不能覆盖的小格子的个数。
Sample Input
1 0.010.356049 0.7988891 0.020.646118 0.801208
Sample Output
25002496
解题思路:
暴力枚举二维区域内的每个点,对于每个点,只要有一个圆能把它覆盖掉就cnt++。提前把方块中心点的坐标存在两个数组里,这里注意起始和间隔。对应本题来说起始应该是0.01,间隔应该是0.02.
完整代码:
#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL; /** Constant List .. **/ //{ const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;int n ;double r; struct node{ double x; double y;}q[10001]; double mx[50];double my[50]; void init(){ memset(mx , 0 , sizeof(mx)); memset(my , 0 , sizeof(my)); double k = 0.01 , t = 0.02; for(int i = 0 ; i < 50 ; i ++) { mx[i] += k; my[i] += k; k += t; }} node temp; double dis(node a , node b){ return sqrt( (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) );} bool judge(node a , node b){ if(dis(a , b) < r) return true; else return false;} int main(){ #ifdef DoubleQ freopen("in.txt","r",stdin); #endif while(~scanf("%d%lf",&n,&r)) { init(); for(int i = 0 ; i < n ; i ++) { scanf("%lf%lf",&q[i].x , &q[i].y); } int cnt = 0; for(int i = 0 ; i < 50 ; i ++) { for(int j = 0 ; j < 50 ; j ++) { for(int k = 0 ; k < n ; k ++) { temp.x = mx[i]; temp.y = my[j]; if(judge(temp , q[k])) { cnt ++; break; } } } } printf("%d\n",2500 - cnt); }}
0 0
- HLJUOJ1122(暴力枚举)
- HDU2566(暴力枚举)
- hdu1015(暴力枚举。。。。)
- Friends (暴力枚举)
- Safecracker(枚举暴力)
- 暴力枚举(刷题)
- “暴力”枚举(穷举)
- hdu 4968(暴力枚举)
- 炸弹人(暴力枚举)
- 1262 - Password (暴力枚举)
- poj 3671(暴力 枚举)
- Friend-Graph(暴力枚举)
- 完美数列(暴力枚举)
- 暴力枚举
- 暴力枚举?
- 暴力枚举
- 暴力枚举
- 暴力枚举
- 图论500题
- jQuery方法
- powershell adsi
- Iphone图像渲染与屏幕适配
- 任何一个能够被3整除的正整数,取各位数字的立方和,再取各位数字的立方和, 重复有限次,必得到 153 这个数,且 153 再重复也还是153
- HLJUOJ1122(暴力枚举)
- 设计模式笔记-策略模式
- 初步了解C++命名空间
- FZU 2137 奇异字符串 字符串哈希
- 算法导论第六章伪码转C++ ___堆排序
- 输入正整数 k,找到所有的正整数 x ≥ y,使得 1/k =1/x + 1/y
- 学习总结
- cookie session 问题总结
- 研磨Hadoop源码(二)-yarn-ClientToAMTokenSecretManagerInRM