UVa 297 四分树
感觉特别像那个分治的日程表问题。是f的话就填,否则就不填,然后同一个表填两次。那么就是最后的结果。
1 #include <iostream> 2 #include <cstring> 3 #include <string> 4 #include <map> 5 #include <set> 6 #include <algorithm> 7 #include <fstream> 8 #include <cstdio> 9 #include <cmath> 10 #include <stack> 11 #include <queue> 12 using namespace std; 13 const double Pi=3.14159265358979323846; 14 typedef long long ll; 15 const int MAXN=5000+5; 16 const int dx[5]={0,0,0,1,-1}; 17 const int dy[5]={1,-1,0,0,0}; 18 const int INF = 0x3f3f3f3f; 19 const int NINF = 0xc0c0c0c0; 20 const ll mod=1e9+7; 21 int a[MAXN][MAXN]; 22 void build(string str,int &cnt,int r1,int r2,int c1,int c2) 23 { 24 char s=str[cnt++]; 25 if(s=='p') 26 { 27 int midr=(r1+r2)/2,midc=(c1+c2)/2; 28 build(str,cnt,r1,midr,midc+1,c2); 29 build(str,cnt,r1,midr,c1,midc); 30 build(str,cnt,midr+1,r2,c1,midc); 31 build(str,cnt,midr+1,r2,midc+1,c2); 32 } 33 else if(s=='f') 34 { 35 //wcout <<"in"; 36 for(int i=r1;i<=r2;i++) 37 for(int j=c1;j<=c2;j++) 38 a[i][j]=1; 39 } 40 41 } 42 43 int main() 44 { 45 int t;cin>>t; 46 while(t--) 47 { 48 int cnt=0; 49 string str1,str2; 50 cin>>str1>>str2; 51 memset(a,0,sizeof(a)); 52 build(str1,cnt,1,32,1,32); 53 /*for(int i=1;i<=32;i++) 54 { 55 for(int j=1;j<=32;j++) 56 { 57 cout <<a[i][j]<<" "; 58 } 59 cout <<endl; 60 }*/ 61 cnt=0; 62 build(str2,cnt,1,32,1,32); 63 int ans=0; 64 for(int i=1;i<=32;i++) 65 { 66 for(int j=1;j<=32;j++) 67 { 68 if(a[i][j]) ans++; 69 } 70 71 } 72 73 printf("There are %d black pixels.\n",ans); 74 } 75 return 0; 76 } 77 78
转载于:https://www.cnblogs.com/Msmw/p/10670744.html
UVa 297 四分树相关推荐
- 非二叉树 UVA297 四分树 Quadtrees
UVA297 四分树 Quadtrees 题意翻译 如图所示,可以用四分图来表示一个黑白图像,方法是用根节点表示整幅图像,然后把行列个分成两等份,按图中的方式编号,从左到右对应4个子节点.如果某子节点 ...
- Quadtrees UVA - 297
题目链接:https://vjudge.net/problem/UVA-297 题目大意:如上图所示,可以用一个四分树来表示一个黑白图像,方法是用根节点表示整副图像,然后把行列各等分两等分,按照图中的 ...
- 四分树(UVa297紫书p160)
题目描述 输入格式 输出格式 题意翻译 如图所示,可以用四分图来表示一个黑白图像,方法是用根节点表示整幅图像,然后把行列个分成两等份,按图中的方式编号,从左到右对应4个子节点.如果某子节点对应的区域全 ...
- 【COGS】1577 [OIBH 练习赛#6]战地统计系统 四分树
传送门:[COGS]1577 [OIBH 练习赛#6]战地统计系统 题目分析:赤果果的四分树哦~,题目分析就不说了,大家看到一定都会,但是我要吐嘈一下数据= =,这题目的数据竟然有一组是错误的!x1 ...
- LOJ#3159. 「NOI2019」弹跳(四分树+dijkstra)
传送门 n2n^2n2暴力显然,考虑优化. 有一种想法是使用四分树/kd-tree/树套树,发现你并不能得到100pts100pts100pts的好成绩(空间会炸掉) 考试的时候比较智熄,先暴力四分树 ...
- UVa 297 - Quadtrees 四叉树, 及其在编码图像的应用
297 - Quadtrees 4898 41.55% 1811 90.39% 题目链接: http://uva.onlinejudge.org/index.php?option=com_online ...
- UVA - 11992 线段树
UVA - 11992 题意:有一个 r*c 的全 0矩阵, 进行 3 种操作. 1 x1 y1 x2 y2 val 表示将(x1,y1,x2,y2)(x1<=x2,y1<=y2)子矩阵中 ...
- UVA 12086 (树状数组)
题目网址:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- uva 12086 - Potentiometers(树状数组)
题目链接:uva 12086 - Potentiometers 题目大意:给定n个整数,两个操作, S x y:把第x个数变成y M x y:计算第x个数到第y个数的总和 解题思路:用num数组记录每 ...
最新文章
- linux同步工具rsync​
- normest--2-范数的条件数估计
- 小波相干wtc matlab,实现时间序列的小波相干性分析,并画出图谱
- @Scheduled不执行的原因
- 在矩池云中保存Conda环境
- log日志显示与写入文件—qt
- fork/join框架Java
- vfp python_2018年VisualFoxPro
- 第一次学游泳技巧_第一次学游泳作文600字(5篇)
- 2040: [蓝桥杯2022初赛] 砍竹子(优先队列)
- 面包屑导航 java_jquery 面包屑导航 具体实现
- 10G数据不用框架快速去重
- asp.net 判断用户是否使用微信浏览器
- 30岁+,大龄青年转行程序员的切身经历
- Infiniband 和 以太网Ethernet 对比
- web远程访问Windows桌面
- VMware出现配置文件 .vmx 是由VMware产品创建,但该产品与此版 VMware workstation 不兼容,因此无法使用--VMware版本不兼容问题
- ORACLE-JDBC-03 UCP连接池
- P4799 [CEOI2015 Day2]世界冰球锦标赛
- 室内停车场车辆定位及导航系统(反向寻车系统)设计与实现
热门文章
- linux 远程调试文件夹,GDB远程调试开发板程序
- 递推算法之滚动数组思维方式
- oracle sql语句 只读,Oracle_SQL语句
- Java8————Stream API
- 双剑合璧————Spring Boot + Mybatis Plus
- python获取mysql中的数据供js调用_详解js文件通过python访问数据库方法
- arraylist下标从几开始_漫画:为什么计算机从 0 开始计数,而不是从 1 开始?
- 2018.9.15,Arduino—流水灯实验报告
- c# url传参不能包含html标签,c#解析包含HTML特殊字符的字符串XElement
- 两文本一图片android,Android富文本编辑器(二):图文混排以及图片上传处理