1249. Ancient Necropolistime limit:5.0 Second
Memory limit:4 mbaerophotography data provide a bitmap picture of a Hard-to-reach region. According to the suggestions of scientists, this region is a cemetery of a extinct civilization. Indeed, the picture, has been converted to a binary form, shows distinctly visible areas, dark (marked with symbols 1) and light (marked with 0). It seems that the dark areas is tombstones. It's easy to either confirm or reject the hypothesis since the race that lived in the region knew astronomy, so tombstones Were always oriented along the Earth ' s parallels and meridians. That's why the dark areas in the picture should has the form of rectangles with the sides parallel to the axes. If it is so and then we indeed has a picture of a cemetery of an extinct race. Otherwise, new hypotheses should be suggested. Inputthe first input line contains and integers
Nand
M, which is the dimensions of the picture provided by the aerophotography. Each of the next
NLines contains
MZeros or ones separated with a space. The numbers
Nand
МDo not exceed 3000.OutputOutput "Yes" if any connected dark areas in the picture is rectangles and "No" otherwise. Samples
input |
Output |
2 20 11 1 |
No |
3 30 0 11 1 01 1 0 |
Yes |
problem Author:Nikita Shamgunov and Leonid Volkov
problem Source:Open Collegiate Programming contest for student teams, Ural state University, March 15, 2003
Tags:None()difficulty:210 Test instructions: In the matrix of n*m, all 1 connected blocks are not rectangles. Analysis: Violence. But note that it is impossible to save the entire picture, so you can only compare it with the next two lines.
1 /**2 Create by Yzx-stupidboy3 */4#include <cstdio>5#include <cstring>6#include <cstdlib>7#include <cmath>8#include <deque>9#include <vector>Ten#include <queue> One#include <iostream> A#include <algorithm> -#include <map> -#include <Set> the#include <ctime> -#include <iomanip> - using namespacestd; -typedefLong LongLL; +typedefDoubleDB; - #defineMIT (2147483647) + #defineINF (1000000001) A #defineMLL (1000000000000000001LL) at #defineSZ (x) ((int) (x). Size ()) - #defineCLR (x, y) memset (x, y, sizeof (x)) - #definePUF Push_front - #definePub push_back - #definePOF Pop_front - #definePOB pop_back in #defineFT first - #defineSD Second to #defineMk Make_pair + -InlineintGetint () the { * intRET =0; $ CharCH =' ';Panax Notoginseng BOOLFlag =0; - while(! (Ch >='0'&& CH <='9')) the { + if(ch = ='-') Flag ^=1; ACH =GetChar (); the } + while(Ch >='0'&& CH <='9') - { $RET = RET *Ten+ CH-'0'; $CH =GetChar (); - } - returnFlag? -Ret:ret; the } - Wuyi Const intN =3010; the intN, M, Graph[n], data[n]; - WuInlinevoidInput () - { About //scanf ("%d%d", &n, &m); $n =Getint (); -m =Getint (); - } - AInlinevoidMove (int&l,int&r,int*arr) + { the for(L = r +1; L <= m &&!arr[l]; l++); - for(r = l; r < m && Arr[r +1]; r++); $ } the theInlinevoidSolve () the { the BOOLAns =1; - for(inti =1; I <= n && ans; i++) in { the for(intj =1; J <= M; J + +) theDATA[J] =Getint (); About the intL1, r1 =0, L2, r2 =0; the for(L1 =1; L1 <= m &&!graph[l1]; l1++); the for(r1 = L1; R1 < m && Graph[r1 +1]; r1++); + for(L2 =1; L2 <= M &&!data[l2]; l2++); - for(r2 = L2; R2 < m && DATA[R2 +1]; r2++); the while(L1 <= m && L2 <=m)Bayi { the if(R1 <L2) Move (L1, R1, graph); the Else if(R2 <L1) Move (L2, R2, data); - Else if(L1 = = L2 && R1 = =R2) - { the Move (L1, R1, graph); the Move (L2, R2, data); the } the Else - { theAns =0; the Break; the }94 } the the for(intj =1; J <= M; J + +) Graph[j] =Data[j]; the }98 AboutPuts (ans?)"Yes":"No"); - }101 102 intMain ()103 {104Freopen ("a.in","R", stdin); the Input ();106 Solve ();107 return 0;108}
View Code
Ural 1249. Ancient Necropolis