Example #1
0
int main() {
  int n, q, x;
  string vs, vt;

#ifndef __WATASHI__
  freopen("shuffle.in", "r", stdin);
  freopen("shuffle.out", "w", stdout);
#endif
  scanf("%d%d%d", &n, &q, &p);
  vs.resize(n);
  vt.resize(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x);
    vs[i] = (char)(x - 1);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x);
    vt[i] = (char)(x - 1);
  }
  for (int i = 0; i < p; ++i) {
    scanf("%d%d", &l[i], &m[i]);
    l[i] = n - l[i];
    m[i] = l[i] - m[i];
  }

  // forward (bfs)
  s.clear();
  s[vs] = "";
  for (int i = 0; i < q / 2; ++i) {
    map<string, string> tmp;
    for (const auto& j: s) {
      for (int k = 0; k < p; ++k) {
        string v = j.first;
        rotate(v.begin(), v.begin() + m[k], v.begin() + l[k]);
        tmp[v] = j.second + (char)('1' + k);
      }
    }
    s.swap(tmp);
  }
  fprintf(stderr, "s.size() = %d\n", (int)s.size());

  // backward (dfs)
  for (int i = 0; i < p; ++i) {
    m[i] = l[i] - m[i];
  }
  try {
    dfs((q + 1) / 2, vt);
    puts("Impossible");
  } catch (string ans) {
    for (int i = 0; i < q; ++i) {
      printf("%c%c", ans[i], i == q - 1 ? '\n' : ' ');
    }
  }

  return 0;
}
Example #2
0
File: map.hpp Project: zoid/ztl
void swap(map<Key, Value, Compare>& _x, map<Key, Value, Compare>& _y) { _x.swap(_y); }
Example #3
0
int main ( int argc, char **argv ) {
    // Verify that the version of the library that we linked against is
    // compatible with the version of the headers we compiled against.
    GOOGLE_PROTOBUF_VERIFY_VERSION;

    signal(SIGSEGV, handler);

    if ( argc < 2 ) {
        cerr << "Require more arguments to run the programme." << "\n";
        return(EXIT_FAILURE);
    }

    // Get all the configs.
    Config cfg;
    // Read the file. If there is an error, report it and exit.
    try {
        cfg.readFile(argv[1]);
    }
    catch ( const FileIOException &fioex ) {
        cerr << "I/O error while reading file." << "\n";
        return ( EXIT_FAILURE );
    }
    catch ( const ParseException &pex ) {
        cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine()
             << " - " << pex.getError() << "\n";
        return(EXIT_FAILURE);
    }

    string port;
    string pull_socket_count;
    string pull_socket;
    string push_socket_samples;
    string push_socket;
    string min_query_length_cfg;
    string max_query_length_cfg;
    string max_query_length_count_threshold_cfg;
    string max_match_reads_cfg;
    string workers;

    try {
        const Setting& rs = cfg.getRoot();
        if ( rs.exists("max_read_length") ) {
            MAX_READ_LENGTH = atoi(cfg.lookup("max_read_length").c_str());
        }
        if ( rs.exists("min_read_length") ) {
            MIN_READ_LENGTH = atoi(cfg.lookup("min_read_length").c_str());
        }

        port = cfg.lookup("port").c_str();
        pull_socket_count = cfg.lookup("pull_socket_count").c_str();
        pull_socket = cfg.lookup("pull_socket").c_str();
        push_socket_samples = cfg.lookup("push_socket_samples").c_str();
        push_socket = cfg.lookup("push_socket").c_str();
        min_query_length_cfg = cfg.lookup("min_query_length").c_str();
        max_query_length_cfg = cfg.lookup("max_query_length").c_str();
        max_query_length_count_threshold_cfg = cfg.lookup("max_query_length_count_threshold").c_str();
        max_match_reads_cfg = cfg.lookup("max_match_reads").c_str();
        workers = cfg.lookup("workers").c_str();
    }
    catch ( const SettingNotFoundException &nfex )
    {
        cerr << "No 'name' setting in configuration file." << "\n";
        return(EXIT_FAILURE);
    }

    workers_count = atoi(workers.c_str());
    min_query_length = atoi(min_query_length_cfg.c_str());
    max_query_length = atoi(max_query_length_cfg.c_str());
    max_query_length_count_threshold = atoi(max_query_length_count_threshold_cfg.c_str());
    max_match_reads = atoi(max_match_reads_cfg.c_str());

    try {
        receiver_count.bind(pull_socket_count.c_str());
        receiver.bind(pull_socket.c_str());
        int hwm = 0;
        sender_samples.setsockopt(ZMQ_SNDHWM, &hwm, sizeof(hwm));
        sender_samples.setsockopt(ZMQ_RCVHWM, &hwm, sizeof(hwm));
        sender_samples.bind(push_socket_samples.c_str());
        sender.bind(push_socket.c_str());
    }
    catch ( const zmq::error_t& er ) {
        cerr << "error in binding with nubmer " << er.num() << "\n";
    }

    std::this_thread::sleep_for(std::chrono::milliseconds( 1 * 6 * 1000));

    pthread_t worker;
    pthread_create(&worker, NULL, worker_routine, NULL);

    pthread_t counter;
    pthread_create(&counter, NULL, counter_routine, NULL);

    struct mg_server *server;

    // Create and configure the server
    server = mg_create_server(NULL, request_handler);
    mg_set_option(server, "listening_port", port.c_str());

    // Serve request. Hit Ctrl-C to terminate the program
    cerr << "start listening on port " << port << "\n";
    for (;;) {
        completed_requests.clear();
        {
            lock_guard<mutex> lg(mtx);
            completed_requests.swap(completed_responses);
        }
        mg_poll_server(server, 10);
    }

    // Cleanup, and free server instance
    mg_destroy_server(&server);

    // Optional:  Delete all global objects allocated by libprotobuf.
    google::protobuf::ShutdownProtobufLibrary();

    return 0;
}