HDU 4462 Scaring the Birds (2012 Hangzhou Field Game J)

Source: Internet
Author: User

1. Title Description: Click to open the link

2. Problem solving ideas: The subject is a simple simulation problem. But the point is to understand the details of the topic. Easy to make 2 understanding errors: (1) mistakenly think that each scarecrow has a different scaring range, in fact scaring range is determined by different vacant intersection, and the Scarecrow has nothing to do with. (2) mistakenly think all points need to be covered, in fact, the topic is required as long as all the corn is protected on the line, the place where the scarecrow is originally open space, there is no protection does not matter. Because the scope of the topic is very small, it is entirely possible to enumerate the collection to determine where the scarecrow is needed, and if the Scarecrow succeeds in protecting all the corn, update ans and then output the minimum value.

But here is a little trick worth learning: Do not need to really cover to the location of all marked as 1, just to the left border is marked 1, the right border is marked by-1 on the line, so that the i,j is protected, only need to see Sum{vis (i,k) |1≤k≤i} is greater than 0, Or even though it is less than 0, it is a vacant space.

3. Code:

#define _crt_secure_no_warnings#include<iostream> #include <algorithm> #include <cassert> #include <string> #include <sstream> #include <set> #include <vector> #include <stack> #include <map> #include <queue> #include <deque> #include <cstdlib> #include <cstdio> #include < cstring> #include <cmath> #include <ctime> #include <cctype> #include <functional>using namespace Std; #define ME (s) memset (s,0,sizeof (s)) #define REP (i,n) for (int i=0;i< (n); i++) #define PB Push_backtypedef  Long long ll;typedef unsigned int uint;typedef unsigned long long ull;typedef pair <int, int> p;const int N = 55;int  Tree[n][n];int g[n][n];int N, k;int x[10], y[10], R[10];int flag[10];bool judge () {for (int i = 1; I <= N; i++) {int tmp = 0;for (int j = 1; J <= N; j + +) {tmp + = tree[i][j];if (tmp <= 0 && g[i][j]! = 1) return false;} return true;} int main () {while (~SCANF ("%d", &n) && N) {scanf ("%d", &k);s = 100;me (g); for (int i = 0; i<k; i++) {scanf ("%d%d", &x[i], &y[i]); G[x[i]][y[i]] = 1;}  for (int i = 0; i<k; i++) scanf ("%d", &r[i]), for (int i = 0; i< (1 << k); i++) {Me (tree); int j = i, p = 0;int TMP = 0;ME (flag), while (j) {flag[p++] = j & 1;tmp + = j & 1;j >>= 1;} for (j = 0; j<k; j + +) if (Flag[j]) {for (P = 1; p <= N; p++) if (ABS (Y[j]-P) <= r[j]) {int wid = R[j]-ABS (Y[J]- p); Tree[p][max (1, X[j]-WID)]++;//left boundary value +1tree[p][min (n + 1, X[j] + wid + 1)]--;//right boundary value -1}}if (judge ()) ans = min (ans, tmp);} if (ans = =) puts ("-1"); else printf ("%d\n", ans);}}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 4462 Scaring the Birds (2012 Hangzhou Field Game J)

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.