int main (void) { std::vector<std::vector<int>> A = { {1,2,3}, {3,4,5}, {5,6,7}}; std::vector<int> S = {1,3,4,6}; auto res = find_sequence(A,S); std::cout << res << std::endl; return 0; }
void test_find_sequence(void){ int n, t; n = t = 0; while( scanf("%d %d", &n, &t) != EOF ){ int a[n]; if(find_sequence(a, n, t, 1000) > -1){ ints_println_basic(a, n); }else{ printf("Impossible\n"); } } }
static int add_data(struct nstx_item *item, struct nstxhdr *pkt, int datalen) { char *payload; payload = ((char *) pkt) + sizeof(struct nstxhdr); item->timestamp = time(NULL); if (pkt->flags & NSTX_LF) { item->frc = pkt->seq+1; } add_data_chunk(item, pkt->seq, payload, datalen-sizeof(struct nstxhdr)); if (item->frc && (find_sequence(item) == item->frc)) { return 1; } return 0; }
bool Project::new_edition( const EditionSessionInfos& session_infos ) { Sequence* sequence = find_sequence( session_infos.sequence_id ); if( sequence ) { auto session = std::unique_ptr< EditionSession >( new EditionSession( *this, *sequence, session_infos.name ) ); emit edition_session_created( *session ); // notify the world! add_edition( std::move(session) ); return true; } return false; }
/* * The following is a work around to deal with how IE7 embeds the local file name * within the Mime header using full WINDOWS file path with backslash directory delimiters. * This section of code attempts to isolate the directory path and remove it * from what is written into the output file. In addition, it changes * esc chars (i.e. backslashes) to forward slashes. * This function has two modes. The first to find a boundary marker. The * second is to find the filename immediately after the boundary. */ static int readmimefile(struct ast_iostream *in, FILE *fout, char *boundary, int contentlen) { int find_filename = 0; char buf[4096]; int marker; int x; int char_in_buf = 0; int num_to_read; int boundary_len; char * path_end, * path_start, * filespec; if (NULL == in || NULL == fout || NULL == boundary || 0 >= contentlen) { return -1; } boundary_len = strlen(boundary); while (0 < contentlen || 0 < char_in_buf) { /* determine how much I will read into the buffer */ if (contentlen > sizeof(buf) - char_in_buf) { num_to_read = sizeof(buf)- char_in_buf; } else { num_to_read = contentlen; } if (0 < num_to_read) { if (ast_iostream_read(in, &(buf[char_in_buf]), num_to_read) < num_to_read) { ast_log(LOG_WARNING, "read failed: %s\n", strerror(errno)); num_to_read = 0; } contentlen -= num_to_read; char_in_buf += num_to_read; } /* If I am looking for the filename spec */ if (find_filename) { path_end = filespec = NULL; x = strlen("filename=\""); marker = find_sequence(buf, char_in_buf, "filename=\"", x ); if (0 <= marker) { marker += x; /* Index beyond the filename marker */ path_start = &buf[marker]; for (path_end = path_start, x = 0; x < char_in_buf-marker; x++, path_end++) { if ('\\' == *path_end) { /* convert backslashses to forward slashes */ *path_end = '/'; } if ('\"' == *path_end) { /* If at the end of the file name spec */ *path_end = '\0'; /* temporarily null terminate the file spec for basename */ filespec = basename(path_start); *path_end = '\"'; break; } } } if (filespec) { /* If the file name path was found in the header */ if (fwrite(buf, 1, marker, fout) != marker) { ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno)); } x = (int)(path_end+1 - filespec); if (fwrite(filespec, 1, x, fout) != x) { ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno)); } x = (int)(path_end+1 - buf); memmove(buf, &(buf[x]), char_in_buf-x); char_in_buf -= x; } find_filename = 0; } else { /* I am looking for the boundary marker */ marker = find_sequence(buf, char_in_buf, boundary, boundary_len); if (0 > marker) { if (char_in_buf < (boundary_len)) { /*no possibility to find the boundary, write all you have */ if (fwrite(buf, 1, char_in_buf, fout) != char_in_buf) { ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno)); } char_in_buf = 0; } else { /* write all except for area where the boundary marker could be */ if (fwrite(buf, 1, char_in_buf -(boundary_len -1), fout) != char_in_buf - (boundary_len - 1)) { ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno)); } x = char_in_buf -(boundary_len -1); memmove(buf, &(buf[x]), char_in_buf-x); char_in_buf = (boundary_len -1); } } else { /* write up through the boundary, then look for filename in the rest */ if (fwrite(buf, 1, marker + boundary_len, fout) != marker + boundary_len) { ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno)); } x = marker + boundary_len; memmove(buf, &(buf[x]), char_in_buf-x); char_in_buf -= marker + boundary_len; find_filename =1; } } } return 0; }
#endif t = t - (t << n); printf("\tFACTOR_REV, %d,",n); break; } return target; } static Node *find_sequence(int c, unsigned int limit); static void try(int factor, Node * node, MulOp opcode) { unsigned int cost = costs[opcode]; unsigned int limit = node->cost - cost; Node *factor_node = find_sequence(factor, limit); if (factor_node->parent && factor_node->cost < limit) { node->parent = factor_node; node->opcode = opcode; node->cost = factor_node->cost + cost; } } static Node * find_sequence(int c, unsigned int limit) { Node *node = lookup(c); if (!node->parent && node->cost < limit) { node->cost = limit; if (c > 0) { int power = 4;