Esempio n. 1
0
File: 776.cpp Progetto: waiwai444/oj
int main()
{
    int i, c;
    for(;;)
    {
        n = m = 0;
        while((c = fgetc(stdin)) != EOF)
        {
            if(c == '%')
            {
                fgetc(stdin);
                break;
            }
            trees[n].push_back(c);
            c = fgetc(stdin);
            if(c == '\n')
                ++n;
        }
        m = trees[0].size();
        solve();
        print_ans();
        if(c == EOF)
            break;
        for(i = 0; i < n; i++)
        {
            trees[i].clear();
            monkeys[i].clear();
        }
    }
    return 0;
}
Esempio n. 2
0
void dfs(int p)
{
    if (p == 16) {
        cnt++;
        if (is_print) print_ans();

        return ;
    }

    char c;
    for (c = 'A'; c <= 'E'; c++)
        if (cow[c]) {
            int i, j;
            for (i = 1; i <= 4; i++)
                for (j = 1; j <= 4; j++)
                    if (can_put(c, i, j)) {
                        if (is_print) ans[p] = (struct Point){c, i, j};

                        char t = map[i][j];
                        map[i][j] = c;
                        cow[c]--;
                        vis[i][j] = 1;

                        dfs(p + 1);

                        vis[i][j] = 0;
                        cow[c]++;
                        map[i][j] = t;
                    }
        }
}
Esempio n. 3
0
int main() {
  int i, j, ans, best;
  scanf("%d", &n);
  for(i = 1; i <= n; i++) {
    scanf("%d%d", &x[i], &y[i]);
    if(x[i] > y[i]) {
      int t = x[i]; x[i] = y[i]; y[i] = t;
    }
  }
  memset(G, 0, sizeof(G));
  for(i = 1; i <= n; i++)
    for(j = 1; j <= n; j++)
      if(x[i] < x[j] && y[i] < y[j]) G[i][j] = 1;

  ans = 0;
  for(i = 1; i <= n; i++)
    if(dp(i) > ans) {
      best = i;
      ans = dp(i);
    }
  printf("%d\n", ans);
  print_ans(best);
  printf("\n");
  return 0;
}
Esempio n. 4
0
void print_ans(int i) {
  printf("%d ", i);
  for(int j = 1; j <= n; j++) if(G[i][j] && d[i] == d[j]+1) {
    print_ans(j);
    break;
  }
}
Esempio n. 5
0
void solve_sudoku(int n)
{
    int p,q,i;
    if(n==81)
    {
        print_ans();
        fill(a,ans,LIGHTGRAY);
        exit(0);
    }
    p=n/9; q=n%9;
    if(ans[p][q]==0)
    {
        for(i=1;i<=9;++i)
        {
            if(place(i,p,q))
            {
                ans[p][q]=i;
                solve_sudoku(n+1);
                ans[p][q]=0;
            }
        }
    }
    else
        solve_sudoku(n+1);
}
void print_ans(int i) //打印字典序最小的路径
{
    cout << i << ' ';
    for (int j = 0; j < n; ++j)
        if (G[i][j] && d[i] == d[j]+1) {
            print_ans(j);
            break;
        }
}
Esempio n. 7
0
int main()
{
    initwindow(600,600,"SU-DO-KU");
    readsudoku();
    print_ans();
    fill(a,ans,BLACK);
    printf("\nThe Solved Su-do-ku:\n");
    solve_sudoku(0);
    getch();
}
Esempio n. 8
0
File: 410.cpp Progetto: waiwai444/oj
int main()
{
    int i, tc = 0;
    while(scanf("%d%d", &c, &s) != EOF)
    {
        for(i = 0; i < s; i++)
            scanf("%d", &m[i]);
        solve();
		printf("Set #%d\n", ++tc);
		print_ans();
    }
    return 0;
}
Esempio n. 9
0
void check_ans(char ** arr_argv, int num_in_arr, char * buffer, int count) {
    int pipefd[2];
    pipe(pipefd);
    
    if (!fork()) {
        arr_argv[num_in_arr] = buffer;
        dup2(pipefd[1], 1);
        execvp(arr_argv[0], arr_argv);
        exit(0);
    }
    int status = 0;
    wait(&status);
    if (is_ok_status(status)) {
        print_ans(buffer, count);
        if (buffer[count - 1] != '\n') {
            println();
        }
    }
}