Ultraviolet A 201-Squares (my own method is better for students)

Source: Internet
Author: User

tag: OS Io for Re C Code

# Include <stdio. h> # include <string. h >#include <string >#include <iostream> # include <algorithm> using namespace STD; int H [20] [20]; int V [20] [20]; int size _ [20]; int n, m; int flag; void judge (int x, int y) // This is the key part of the code to determine whether it can constitute square; {int a1 = N-X; int a2 = N-y; int AA = min (a1, a2); For (INT I = 0; I <AA; I ++) {If (H [x] [Y + I] & V [x + I] [Y]) {Int J; For (j = 0; j <= I; j ++) {If (! (H [x + I + 1] [Y + J]) |! (V [x + J] [Y + I + 1]) {break;} If (j = I) {flag = 1; size _ [I] ++ ;}}} else break ;}} int main () {int Kase = 0; while (scanf ("% d", & N )! = EOF) {scanf ("% d", & M); Kase ++; flag = 0; memset (size _, 0, sizeof (size _)); memset (H, 0, sizeof (h); memset (v, 0, sizeof (v); int a1, a2; string s; For (INT I = 0; I <m; I ++) {CIN> S> A1> A2; If (S = "H ") {H [a1] [a2] = 1;} If (S = "v") {v [a2] [a1] = 1 ;}} for (INT I = 1; I <= N; I ++) {for (Int J = 1; j <= N; j ++) {If (H [I] [J] & V [I] [J]) {judge (I, j) ;}} if (Kase! = 1) printf ("\ n **********************************\ N "); printf ("problem # % d \ n", Kase); If (flag = 1) {for (INT I = 0; I <20; I ++) {If (size _ [I]! = 0) {printf ("% d square (s) of size % d \ n", size _ [I], I + 1 );}}} else printf ("no completed squares can be found. \ n ") ;}return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.