ZOJ Problem Set - 1788 Quad Trees
Chieh
posted @ 2018年3月13日 15:38
in NO Answer No Speak
, 535 阅读
根据题意模拟即可
// // main.cpp // zoj1788 // // Created by cfhaiteeh on 13/03/2018. // Copyright © 2018 cfhaiteeh. All rights reserved. // #include <iostream> #include <cstring> #include <cmath> #include <cstdio> #include <queue> using namespace std; const int maxn=1234567; struct he{ int x1,y1,x2,y2; }; int ai[maxn]; int mat[513][513]; int T,n; void init(){ scanf("%d",&n); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) scanf("%d",&mat[i][j]); } int st; bool getCmp(int x1,int y1,int x2,int y2){ int cmp=mat[x1][y1]; for(int i=x1;i<=x2;i++){ for(int j=y1;j<=y2;j++){ if(mat[i][j]!=cmp)return 0; } } return 1; } queue<he> Q; void pushQ(int x1,int x2,int y1,int y2){ he c; c.x1=x1; c.x2=x2; c.y1=y1; c.y2=y2; Q.push(c); } void BFS(){ he fir; fir.x1=1; fir.y1=1; fir.x2=n; fir.y2=n; st=0; Q.push(fir); while(!Q.empty()){ he c=Q.front(); Q.pop(); bool flag=getCmp(c.x1, c.y1, c.x2, c.y2); if(flag){ ai[++st]=0; ai[++st]=mat[c.x1][c.y1]; } else{ ai[++st]=1; int mid1=(c.x1+c.x2)/2; int mid2=(c.y1+c.y2)/2; pushQ(c.x1, mid1, c.y1, mid2); pushQ(c.x1,mid1,mid2+1,c.y2); pushQ(mid1+1, c.x2, c.y1, mid2); pushQ(mid1+1,c.x2,mid2+1,c.y2); } } } char ans[maxn]; int ci[]={1,2,4,8}; char getChar(int t){ int s=0; for(int i=0;i<4;i++){ s=s+ai[t]*ci[i]; t--; if(t==0)break; } if(s>10){ s-=10; return s+'A'; } return s+'0'; } int now; void play(){ if(!Q.empty()){ Q.pop(); } BFS(); now=0; for(int i=st;i>=1;i-=4){ ans[++now]=getChar(i); } } void pri(){ for(int i=now;i>=1;i--)printf("%c",ans[i]); printf("\n"); } int main() { // insert code here... scanf("%d",&T); while(T--){ init(); play(); pri(); } return 0; }
2018年9月03日 08:12
It is completely okay to do that. I remember I had to take some https://ukessaysreviews.com/descriptive-essay help when I forgot to write more often. So please do not apologize for this.
2018年10月13日 01:13
what a superb blog you have! I must appreciate that you have been doing a terrific job by serving the community of older people and helping them to live a happy and productive lives.
2019年11月28日 21:01
Different parts of sofa have to have different cleanup techniques determined by their textile and a higher level soiling. In Perfectly Cleanup Services, we arrange and search at the piece ahead of cleaning. Our qualified cleaning know-how helps people deciding the top method to work with and keep your upholstery is just not damaged the slightest bit.
2020年4月25日 04:16
A retail complex is a good building or simply several homes that mode a procuring complex. During this shopping challenging, there happen to be several merchandisers depicted, with interconnecting walk options allow any mall visitors to move in shopping unit into the other conveniently.
2020年4月25日 04:17
On earth do you do on line shopping any old-fashioned strategy? Do buy search engines to choose the item you like? Shopping traits have revolutionized together with evolved even to another level when using the phenomenon for social procuring networks.
2020年4月25日 04:17
Holiday for market was a key feature since the beginning of civilisation. The opening at Lothal was a key centre for trade amongst the Indus pit civilisation and also Sumerian civilisation.
2020年4月25日 04:18
Famous travel bargain sites. You can search and get travel is about carrentals.com, Orbiz, Delta Air Lines, Travelocity, Expedia, travel.yahoo.com, travelchannel.com, travel.nytimes.com, cnn.com, and County Visitors Bureaus. For US citizen traveling abroad, try travel.state.gov..
2020年4月25日 04:18
Browsing the documents online together with watching 24-hour current information sites is becoming more and more popular. The reason is , it is certainly cheaper also, you get even more news. You will find what is happening worldwide, as it all happens.