HDU 4499 Cannon (brute force solution)

Source: Internet
Author: User

Test instructions: Given a n*m chess board, put some pieces, ask you can put a few guns (Chinese chess gun).

Analysis: Actually very simple, because the chessboard is 5*5 biggest, then the direct violence on the line, can be regarded as a line, very water, time is very short, only 62ms.

The code is as follows:

#include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream > #include <cstring> #include <set> #include <queue> #include <algorithm> #include <vector > #include <map> #include <cctype>using namespace std; typedef long Long Ll;typedef pair<int, int> p;c onst int inf = 0x3f3f3f3f;const double inf = 0x3f3f3f3f3f3f3f;const double EPS = 1e-8;const int maxn = 1e4 + 5;const int D R[] = {0, 0,-1, 1};const int dc[] = {-1, 1, 0, 0};int N, m;inline bool is_in (int r, int c) {return R >= 0 &&amp ; R < n && C >= 0 && C < m;}    int a[30];int ans;bool isly (int x) {int b[] = {x+1, x-1, X+m, x-m};    int d[] = {x/m*m+m-1, x/m*m, n-1, 0};        int c[] = {1,-1, M,-m};        for (int i = 0; i < 4; ++i) {bool OK = false; for (int j = B[i]; (I & 1 J >= D[i]: J <= D[i]); J + = C[i]) {if (ok && a[j]! =-1) {if (a[j] = = 1) return false;            else break;        } else if (!ok && a[j]! =-1) ok = true; }} return true;    void Dfs (int x, int cnt) {ans = max (ans, CNT);        for (int i = x; i < n; ++i) {if (a[i]! =-1 | |!isly (i)) continue;        A[i] = 1;        DFS (i+1, cnt+1);    A[i] =-1;    }}int Main () {int C;        while (scanf ("%d%d%d", &n, &m, &c) = = 3) {n *= m;        Memset (A,-1, sizeof (a));            for (int i = 0; i < C; ++i) {int x, y;            scanf ("%d%d", &x, &y);        A[x*m+y] = 0;        } ans = 0;        DFS (0, 0);    printf ("%d\n", ans); } return 0;}

HDU 4499 Cannon (brute force solution)

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.