Blue Bridge Cup previous questions about several times choose a card to ask the big God first of all, I have a problem with my code! Do not like to enter, if there is intention, can discuss, I Baidu not to the problem

Source: Internet
Author: User

Previous questions about several times Select card time limit: 1.0s memory limit: 256.0MBProblem description at leisure, Sherlock Holmes and Watson played a game:
There are n integers written on the n card. The two men took turns to take a card. The number required for the next person must be an approximate or multiple of the number that the previous person took. For example, the number "6" is written on a card taken by Sherlock Holmes, and then the figures that Watson can take include:
6,12,18,24, ....
When it is time for a party to pick up a card, the card that does not meet the requirements is optional, and the party is the loser.
Please take advantage of the advantages of the computer to calculate, in the known all cards on the number and the optional number of the conditions, how to choose to ensure victory!
When multiple numbers are selected to win, the smallest number is output. If you lose anyway, output-1. Input format input data is 2 rows. The first line is a number of spaces separated by integers (each integer between 1~100), representing all the cards that are currently remaining.
The second line is also an integer separated by a number of spaces, indicating the number that can be selected. Of course, the number in the second row must be fully contained in the first row of numbers. Output format program will be output to win the Gongfu!! Sample Input 2 3 6
3 6 Sample Output 3 Sample input 1 2 2 3 3 4 5
3 4 5 Sample output 4 My code is a lot of problems, even I can not find out ... I can't get through the second set of test data on the topic. But the first set of data submitted after the test data, can be over, the back is time-out, I wrote two code, a code is set up a super source point 0, and then with the option to connect, and then find out the SG function, there is to each of the optional nodes are the SG function, anyway, it is very depressed, engaged in an afternoon, also no progress , if you are interested, we can discuss and exchange together, I really want to solve this problem now. Please do this problem of people, do not mean to share your knowledge, thank you ~
Because the code changes several times, it is very difficult to see.First code:
#include <cstdio> #include <cstring> #include <algorithm> #define MAX 110using namespace std; int Sg[max ] int num1[200], num2[200]; bool Graph[max][max],visited[max]; int get (char ch[], int num[]) {gets (ch); int len = strlen ( CH), index = 1;for (int i = 0; i < len; ++i) {if (ch[i] = = ") {++index;} Else{num[index] = num[index]*10+ch[i]-' 0 ';}} return index+1;}  int len1, len2; int getsg (int index) {bool Hash[max], flag = False;memset (hash,false,sizeof (hash)); for (int i = 0; i < Len1; ++i) {if (!visited[i] && graph[index][i]) {flag = true;visited[i] = true; HASH[GETSG (i)] = true; Visited[i] = false; }}for (int i = 0; i < MAX; ++i) {if (!hash[i]) {//if (sg[index] = = 0) return sg[index]=i;}} int bsearch (int x) {int i = 1, j = len1-1; while (i<=j) {int mid = (i+j) >>1; if (num1[mid]>x) {j = mid-1;} else if (num1[mid]<x) {i = mid+1;} Else{return Mid;}} return i;} BOOL CMP (const int A, const int b) {return a<b;} int main () {char line1[200],line2[200];len1= Get (line1, num1); len2 = Get (line2, num2); sort (num1+1,num1+len1,cmp); sort (num2+1,num2+len2,cmp); for (int i = 1; I &lt ; Len1; ++i) {for (int j = 1; j < i; ++j) {if (num1[i]%num1[j] = = 0 | | num1[j]%num1[i]==0) {GRAPH[I][J] = graph[j][i] = true;}} for (int i = 1; i < len2; ++i) {int x = bsearch (Num2[i]), j = x;while (num1[--j] = = Num2[i]) {graph[0][j] = true;} j = x; while (num1[j++] = = Num2[i]) {graph[0][j] = true;}} memset (sg,-1,sizeof (SG)); visited[0] = true; GETSG (0); if (sg[0] = = 0) {puts ("-1");} else{for (int i = 1; i < len2; ++i) {int x = bsearch (Num2[i]), if (sg[x]==0) {printf ("%d\n", Num2[i]); return 0;}
with June

Blue Bridge Cup previous questions about several times choose a card to ask the big God first of all, I have a problem with my code! Do not like to enter, if there is intention, can discuss, I Baidu not to the problem

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.