Noj 1173 (Ningbo) birdlike angry pig (brute force enumeration)

Source: Internet
Author: User
  • Http://ac.nbutoj.com/Problem/view.xhtml? Id = 1173
  • [2, 1173] birdlike angry pig
  • Time Limit: 1000 MS memory limit: 65535 K
  • Problem description
  • there's no end to revenge. pigs like to eat birds 'eggs, so birds decide to revenge. for this, pigs decide to revenge as well. pigs give a task to a birdlike pig. they let he sneak into the birds group so that they can destroy the birds group.
    every bird has a ID number (it may not be unique ). to let pigs knoW, the birdlike pig makes the "and operation" amount all the birds 'id number and sign himself to the answer.

     For example: birds are signed as 5, 3, 4. so the birdlike pig signs himself as (5 & 3 & 4 = 0 ). 

    one day, a group birds pass by pigs 'home. so the angry pig want to know whether the birdlike pig is in.

  • Input
  • This problem has several cases. the first line of each case is an integer N (2 <= n <= 100 000 ). then follows a line with N integers, indicates the ID of each bird/birdlike pig.
  • Output
  • For each case, if you can find the birdlike pig then output the ID of birdlike pig. or output 'Caution: No birdlike '.
  • Sample Input
  • 54 0 3 4 5
  • Sample output
  • 0
  • Ideas:
  • The title indicates that the birds and pigs are disguised in the birds group. The value of the birds and pigs is the sum of the birds group values (&). The birds and pigs are set to d, and the birds are set to a, B, c, then A & B & C = D;
  • Now the question gives a sequence and asks if the bird or pig is in this sequence. So as long as the sequence satisfies a number value equal to the phase Set (&) of other numbers, the number is the bird or pig;
  • Now I want to define three arrays A, B, C; A to store the input number, and B to store the N items in front of array (&), C contains the plus N items and sets (&) in array (&);
  • Suppose a contains a, B, c, d;
  • A =>BC d
  • B =>AA & B & C & D
  • C ==> A & B & C & DC & DD

If a [I] = B [I-1] & C [I + 1], then a [I] is a pig

 

Code: C ++

 

 1 # Include <iostream> 2 # Include <stdio. h> 3 # Include <math. h> 4 # Include <algorithm> 5 # Include < String . H> 6 # Include < String > 7 # Include <ctime> 8 # Include <queue> 9 # Include <list> 10 # Include <map> 11 # Include < Set > 12   # Define INF 999999999 13   # Define Maxn 10000000 14   Using   Namespace  STD; 15   16   Int A [ 100010 ], B [ 100010 ], C [ 100010  ];  17   Int  Main ()  18   {  19       Int  N;  20       While (~ Scanf ( "  % D  " ,& N ))  21   {  22           Int  I;  23           For (I = 1 ; I <= N; I ++ )  24 Scanf ( "  % D " ,& A [I]);  25 B [ 0 ] =- 1  ;  26           For (I = 1 ; I <= N; I ++ )  27 B [I] = (B [I- 1 ] & A [I]);  28 C [n + 1 ] =- 1  ;  29           For (I = N; I> 0 ; I -- )  30 C [I] = (C [I + 1 ] & A [I]);  31           For (I = 1 ; I <= N; I ++ )  32               If (B [I-1 ] & C [I + 1 ]) = A [I])  33   {  34 Printf ( "  % D \ n  "  , A [I]);  35                   Break  ;  36   }  37          If (I> N)  38 Printf ( "  Caution: No birdlike \ n  "  );  39   }  40       Return   0  ;  41 }

 

 

 

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.