Exemplo n.º 1
0
void dfs_ss(int x, int y, int id)
{	
	int i, n;
	if (ss[x][y] != -1 || x < 0 || x >= 9 || y < 0 || y >= 9)  return;
	ss[x][y] = id;
	n = desc[x][y] & 15;
	map[x][y] = n;
	if (n == 0) {
		hx[h_cnt] = x;
		hy[h_cnt] = y;
		h_cnt++;
		//printf("%d:%d, %d   ", h_cnt,  x, y);
	} 
	else {
		bit_set(col[y], n);
		bit_set(row[x], n);
		bit_set(block[block_id(x,y)], n);
		bit_set(grid[id], n);
	}

	for (i = 0; i < 4; ++i) {
		if ((desc[x][y] & wall[i]) == 0) {
			dfs_ss(x+_x[i], y+_y[i], id);
		}
	}
}
Exemplo n.º 2
0
void SIPServer::handle_GET(int mpi_source, int get_tag) {
	const int recv_data_count = BlockId::MPI_BLOCK_ID_COUNT + 1;
	const int line_num_offset = BlockId::MPI_BLOCK_ID_COUNT;
	int recv_buffer[recv_data_count];
	MPI_Status status;

	//receive the GET message (Block ID & Line Number)
	SIPMPIUtils::check_err(MPI_Recv(recv_buffer, recv_data_count, MPI_INT, mpi_source, get_tag,
					MPI_COMM_WORLD, &status));
	check_int_count(status, recv_data_count);

	last_seen_line_ = recv_buffer[line_num_offset];
	last_seen_worker_ = mpi_source;

	server_timer_.start_timer(last_seen_line_, ServerTimer::TOTALTIME);

	//construct a BlockId object from the message contents and retrieve the block.
	BlockId::mpi_block_id_t buffer;
	std::copy(recv_buffer, recv_buffer + BlockId::MPI_BLOCK_ID_COUNT, buffer);
	BlockId block_id(buffer);


	size_t block_size = sip_tables_.block_size(block_id);

	server_timer_.start_timer(last_seen_line_, ServerTimer::BLOCKWAITTIME);
	ServerBlock* block = disk_backed_block_map_.get_block_for_reading(block_id);
	server_timer_.pause_timer(last_seen_line_, ServerTimer::BLOCKWAITTIME);

	SIP_LOG(std::cout << "S " << sip_mpi_attr_.global_rank()
			<< " : get for block " << block_id.str(sip_tables_)
			<< ", size = " << block_size
			<< ", sent from = " << mpi_source
			<< ", at line = " << last_seen_line_
			<< std::endl;)
Exemplo n.º 3
0
Move Move::mirror() const
{
    if (is_pass())
	return PASS;
    int d = (direction() + (direction() & 1 ? 5 : 3)) & 7;
    Rotation* rot = &block_set[block_id()]->rotations[d];
    int new_x = y() + rot->offset_x;
    int new_y = x() + rot->offset_y;
    return Move(new_x, new_y, rot->piece->id);
}
Exemplo n.º 4
0
const char* Move::fourcc() const
{
    static char buf[5];
    if (is_pass())
	strcpy(buf, "----");
    else
	sprintf(buf, "%2X%c%d",
		(m_ & 0xff) + 0x11, 'u' - block_id(), direction());
    return buf;
}
 utility::string_t basic_cloud_block_blob_ostreambuf::get_next_block_id()
 {
     utility::ostringstream_t str;
     str << m_block_id_prefix << U('-') << std::setw(6) << std::setfill(U('0')) << m_block_list.size();
     auto utf8_block_id = utility::conversions::to_utf8string(str.str());
     std::vector<unsigned char> block_id_as_array(utf8_block_id.cbegin(), utf8_block_id.cend());
     utility::string_t block_id(utility::conversions::to_base64(block_id_as_array));
     m_block_list.push_back(block_list_item(block_id));
     return block_id;
 }
Exemplo n.º 6
0
void dfs(int k)
{
	int i, j, x, y;
	if (k == h_cnt) {
		ans_cnt++;
		if (ans_cnt == 1) {
			for (i = 0; i < 9; ++i ) {
				for (j = 0; j < 9; ++j) {
					desc[i][j] = map[i][j];
					printf("%d", map[i][j]);
				}
				printf("\n");
			}
		}
		return;
	}
	x = hx[k];
	y = hy[k];
	if (map[x][y] != 0) for(;;) printf("error\n");
	for (i = 1; i <= 9; ++i) {
		if (  !(bit_test(col[y], i) || bit_test(row[x], i) 
			|| bit_test(block[block_id(x,y)], i) || bit_test(grid[ss[x][y]], i)) ) {
			
			bit_set(col[y], i);
			bit_set(row[x], i);
			bit_set(block[block_id(x,y)], i);
			bit_set(grid[ss[x][y]], i);
		
			//printf("test %d: %d,%d : %d\n", k, x, y, i);
				
			map[x][y] = i;
			dfs(k+1);
			map[x][y] = 0;
			
			bit_set_0(col[y], i);
			bit_set_0(row[x], i);
			bit_set_0(block[block_id(x,y)], i);
			bit_set_0(grid[ss[x][y]], i);
		}
		if (ans_cnt > 1) return;
	}
}
Exemplo n.º 7
0
void dfs(int k)
{
    int i, x, y, n;
	if (k >= h_cnt) {
		ans_cnt++;
		//if (ans_cnt == 1) {
		    //memcpy(desc, map, sizeof(map));
		    p_map();
		    fflush(stdout);
		//}
		return;
	}
	x = hx[k];
	y = hy[k];
	for (n = num[x][y][0]; n > 0; --n) {
	    i = num[x][y][n];
		if ( !(
            bit_test(col[y], i) ||
            bit_test(row[x], i) ||
            bit_test(block[block_id(x,y)], i)  ) )
        {
			bit_set(col[y], i);
			bit_set(row[x], i);
			bit_set(block[block_id(x,y)], i);

			map[x][y] = i;
			dfs(k+1);
			map[x][y] = 0;

			bit_set_0(col[y], i);
			bit_set_0(row[x], i);
			bit_set_0(block[block_id(x,y)], i);

            //if (ans_cnt >= 1) return;
		}
	}
}
Exemplo n.º 8
0
int is_in_cache(struct cache *cache, unsigned long entry) {
  int id_block = block_id(cache, entry);
  struct block *block = cache->blocks[id_block];
  int nb_ways = cache->nb_ways;

  struct line *line;
  int i;
  for (i=0; i<nb_ways; i++) {
    line = block->lines[i];
    if (is_valid(line) && (line->first_case == entry / cache->linesize * cache->linesize)) {
      return 1;
    }
  }    
  return 0;
}
Exemplo n.º 9
0
struct line *line_in_cache(struct cache *cache, unsigned long entry) {
  int id_block = block_id(cache, entry);
  struct block *block = cache->blocks[id_block];
  int nb_ways = cache->nb_ways;

  struct line *line;
  int i;
  for (i=0; i<nb_ways; i++) {
    line = block->lines[i];
    if (line->first_case == entry / cache->linesize * cache->linesize) {
      return line;
    }
  }
  fprintf(stderr, "Error: data not present is an inclusive cache\n");
  exit(1);
}
Exemplo n.º 10
0
void pre_work()
{
    int x, y, n;
    for (x = 0; x < 9; ++x) {
        for (y = 0; y < 9; ++y) {
            num[x][y][0] = 0;
            for (n = 1; n <= 9; ++n) {
                if ( !(
                    bit_test(col[y], n) ||
                    bit_test(row[x], n) ||
                    bit_test(block[block_id(x,y)], n) /*||
                    bit_test(grid[ss[x][y]], n) */     ) )
                {
                    num[x][y][++num[x][y][0]] = n;
                }
            }
        }
    }
}
Exemplo n.º 11
0
int main()
{
    freopen("sudoku.in", "r", stdin);
    freopen("sudoku.out", "w", stdout);

	int cs, nCase;
	int i, j, id;
	scanf("%d", &nCase);
	for (cs = 1; cs <= nCase; ++cs) {
	    printf("Case %d:\n", cs);
	    h_cnt = 0;
	    memset(col, 0, sizeof(col));
		memset(row, 0, sizeof(row));
		memset(block, 0, sizeof(block));
		for (i = 0; i < 9; ++i) {
			for (j = 0; j < 9; ++j) {
				scanf("%d", &map[i][j]);
				bit_set(col[j], map[i][j]);
                bit_set(row[i], map[i][j]);
                bit_set(block[block_id(i,j)], map[i][j]);
				if (map[i][j] == 0) {
                    hx[h_cnt] = i;
                    hy[h_cnt++] = j;
				}
			}
		}

        pre_work();
		ans_cnt = 0;
		dfs(0);
	}

    fclose(stdin);
    fclose(stdout);

	return 0;
}
Exemplo n.º 12
0
void update_lines(struct cache *cache, unsigned long entry) {
  int id_block = block_id(cache, entry);
  struct block *block = cache->blocks[id_block];
  int nb_ways = cache->nb_ways;
  cache->update_line(block, nb_ways, entry);
}