2019-08-10 Jizhong NOIP simulation game in group B

T1 [JZOJ1235] flood

Title Description

  One day, a sketch artist in the forest, suddenly broke out in torrents, he needs to return home as soon as possible, there is safe.

  Map forest by R rows C composed of columns, a blank area of ​​the point. "" Indicates, the area floods with "*" indicates that, while the rock with an "X", another artist's residence with "D" represents the artist with "S "means.

  The following points should be noted:

  1, every minute a painter movable frame in four directions (up, down, left, right)

  2, every minute flood four directions can spread to adjacent lattice (blank areas)

  3, floods and painters can not rock the region

  4, the painter can not flood the area (at the same time does not work, that the artist can not be moved to a grid, the grid while the painter was reached to spread the flood, which is not allowed)

  5, floods spread less than the artist's residence

  Give you a map of the forest, programming output at least how long it takes to catch up from a starting position back home (if the artist can not return home safely output "KAKTUS").

data range

  $ 2 \ leq R, C \ leq 50 $

analysis

  I heard today to increase the difficulty, the result is a water problem start

  First $ BFS $ pretreatment area first to be spread out each time of the flood, then $ BFS $ allow artists to be able to walk along way to go, if we can reach the minimum number of steps on the output, otherwise the output $ KAKTUS $

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define N 55

int n, m, x0, y0, x1, y1;
int t[N][N], d[N][N], vis[N][N];
int dir[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};
char g[N][N];

struct Point {
    int x, y;
} p;

bool check(int x, int y) {
    if (x < 1 || x > n) return false;
    if (y < 1 || y > m) return false;
    if (g[x][y] == 'X') return false;
    return true;
}

void bfs(int x, int y) {
    queue<Point> q;
    t[x][y] = 0;
    p.x = x; p.y = y; q.push(p);
    while (!q.empty()) {
        Point temp = q.front(); q.pop();
        for (int i = 0; i < 4; i++) {
            int dx = temp.x + dir[i][0];
            int dy = temp.y + dir[i][1];
            if (check(dx, dy) && g[dx][dy] != 'D')
                if (t[temp.x][temp.y] + 1 < t[dx][dy]) {
                    t[dx][dy] = t[temp.x][temp.y] + 1;
                    p.x = dx; p.y = dy; q.push(p);
                }
        }
    }
}

void BFS() {
    queue<Point> q;
    memset(d, 0x3f, sizeof d);
    d[x0][y0] = 0;
    p.x = x0; p.y = y0; q.push(p);
    while (!q.empty()) {
        Point temp = q.front(); q.pop();
        for (int i = 0; i < 4; i++) {
            int dx = temp.x + dir[i][0];
            int dy = temp.y + dir[i][1];
            if (check(dx, dy) && !vis[dx][dy])
                if (d[temp.x][temp.y] + 1 < t[dx][dy]) {
                    d[dx][dy] = d[temp.x][temp.y] + 1;
                    if (g[dx][dy] == 'D') return;
                    p.x = dx; p.y = dy; q.push(p);
                    vis[dx][dy] = 1;
                }
        }
    }
}

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) {
            scanf(" %c", &g[i][j]);
            if (g[i][j] == 'S') x0 = i, y0 = j;
            if (g[i][j] == 'D') x1 = i, y1 = j;
        }
    memset(t, 0x3f, sizeof t);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            if (g[i][j] == '*') bfs(i, j);
    BFS();
    if (d[x1][y1] == inf) printf("KAKTUS\n");
    else printf("%d\n", d[x1][y1]);
    
    return 0;
}
View Code

T2 [JZOJ1236] Bond I

Title Description

  Everyone knows James Bond, the famous 007, but few people know that a lot of his personal mission is not complete, but by his cousin Jimmy Bond had completed (he has a lot cousin), James tired of assign a task to one Jimmy, he turned to you.

  Every month, James will receive a number of tasks, based on the experience of his mission before he calculated the completion of each task every Jimmy success rate, it requires that each task must be assigned to different people to complete, each person only to complete a task.

  Please write a program to find a distribution plan so that the maximum probability that all tasks are completed successfully.

data range

  $ 1 \ leq N \ leq 20 $

analysis

  Obviously the DP-shaped pressure $ $

  Represent each state has been assigned the task of personnel situation, and then complete enumeration of $ k $ task in binary person ($ k $ is the current status of completed tasks), takes the maximum value in all predecessor states

  The last owner of the largest probability assigned to the task of the state is the answer obtained

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define N 21

int n, m, sum[1 << N];
double g[N][N], f[1 << N];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) {
            scanf("%d", &m);
            g[i][j] = m / 100.0;
        }
    f[0] = 1; sum[0] = 0;
    for (int s = 1; s < (1 << n); s++)
        for (int i = 1; i <= n; i++)
            if (s & (1 << i - 1)) {
                int last = s ^ (1 << i - 1);
                if (!sum[s]) sum[s] = sum[last] + 1;
                f[s] = max(f[s], f[last] * g[i][sum[s]]);
            }
    printf("%.6lf\n", f[(1 << n) - 1] * 100.0);
    
    return 0;
}
View Code

 

T3 [JZOJ1237] table

Title Description

  You just bought a new house home, want to invite a friend to celebrate, so it is necessary to hold a large dining table, dining table can accommodate the number of people equal to the circumference of the table, you want to buy a can accommodate up to people's dining table, side table must parallel with the side of the room.

  Enter the "." Is an empty area, "X" represents an obstacle, the area occupied by the table must be blank.

  To design your room, up to calculate the number of guests invited.

data range

  $ 1 \ leq R, C \ leq 2 \ times 10 ^ $ 3

analysis

  Sample topics so that we see very ignorant force , the original number of guests at the table is a master of long minus

 

Guess you like

Origin www.cnblogs.com/Pedesis/p/11332557.html