ACM-ICPC North America Qualifier Eight Queens

Source: Internet
Author: User

Test instructions: Ask if the picture meets the eight queens.

Problem solving ideas: HASH,DP, bit arithmetic

Problem Solving Code:

My rub code.

1 //File name:a.cpp2 //Author:darkdream3 //Created time:2015 March 14 Saturday 12:00 44 seconds4 5#include <vector>6#include <list>7#include <map>8#include <Set>9#include <deque>Ten#include <stack> One#include <bitset> A#include <algorithm> -#include <functional> -#include <numeric> the#include <utility> -#include <sstream> -#include <iostream> -#include <iomanip> +#include <cstdio> -#include <cmath> +#include <cstdlib> A#include <cstring> at#include <ctime> - #defineLL Long Long -  - using namespacestd; - Charstr[Ten][Ten]; - inthsh[Ten]; in inthsl[Ten]; - inthshl[ -]; to inthslh[ -]; + intMain () { -      while(SCANF ("%s", &str[1][1]) !=EOF) the     { *         for(inti =2; I <=8; i + +) $        {Panax Notoginsengscanf"%s", &str[i][1]); -        } thememset (HSH,0,sizeof(HSH)); +memset (HSL,0,sizeof(HSH)); Amemset (HSHL,0,sizeof(HSHL)); thememset (HSLH,0,sizeof(HSLH)); +        intOK =0 ;  -         for(intI=1; I <=8; i + +) $        { $            for(intj =1; J <=8; j + +) -           { -               if(Str[i][j] = ='.') the                   Continue; -               if(Hsh[i] = =1)Wuyi               { theOK =1;  -}Else{ WuHsh[i] =1 ; -               } About                $               if(Hsl[j] = =1) -               { -OK =1;  -}Else{ AHSL[J] =1 ; +               } the  -               if(hshl[j-i+ -] ==1) $               { theOK =1;  the}Else{ theHshl[j-i + -] =1 ; the               } -  in               if(Hslh[j+i] = =1) the               { theOK =1;  About}Else{ theHslh[j+i] =1 ; the               } the           } +  -        } the        if(OK = =1 )Bayiprintf"invalid\n"); the        Elseprintf"valid\n"); the     } -       -      the     return 0; the}
View Code

Then I saw the bit arithmetic code of the Learning brother:

1#include <iostream>2#include <vector>3#include <cstdio>4#include <cstring>5 using namespacestd;6 Charchess[Ten][Ten];7 intSTU1 =0, STU2 =0, flag =0;8 intMain () {9      for(inti =0; I <8; i++) gets (Chess[i]);Ten      for(inti =0; I <8; i++) { One          for(intj =0; J <8; J + +) A             if(Chess[i][j] = ='*') -                 if(! (STU1 &1<< j) &&! (STU2 &1<<j)) -STU1 |=1<< J, Stu2 |=1<<J; the                 Else { -Flag =1; Break; -                 } -         if(flag) Break; +STU1 <<=1, STU2 >>=1; -     } +     if(flag) puts ("Invalid"); A     ElsePuts"valid"); at}
View Code

ACM-ICPC North America Qualifier Eight Queens

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.