校内题目大美江湖

1.大美江湖 
【题目背景】
细雪飘落长街,枫叶红透又一年
不只为故友流连,其实我也恋长安
听门外足音慢,依稀见旧时容颜
故事几经悲欢,结局都与你有关
——银临《大美江湖》
【问题描述】 扶苏听着《大美江湖》,在剑三里控制着他的人物炮姐来到了长安。 长安城中有一个任务,需要扶苏进入地下的机关道,机关道是一个 n×m 的矩形地 图,里面有一些怪物和药水。扶苏操控着炮姐在机关道中游荡。有些时候他希望问问你 他的角色有多少攻击力、防御力以及丢失了多少血量。 具体的,在输入文件中会给出一个 n×m 的矩形地图,地图中第 i 行第 j 列的字符 Ci,j 代表机关道中第 i 行第 j 列的元素是什么。具体的,Ci,j{‘.’,‘R’,‘Q’,‘Y’,‘M’}。 其中, 1、字符 . 代表此处可以通过,且无其他元素 2、字符 R 代表此处为生命药水,可以减少炮姐 10 点丢失的血量 HP 3、字符 Q 代表此处为力量药水,可以增加炮姐 5 点攻击力 ST 4、字符 Y 代表此处为防御药水,可以增加炮姐 5 点防御力 DE 5、字符 M 代表此处为怪物,炮姐会损失相应血量 每只怪物都有三个参数来描述他们的属性,分别是血量 HPenemy,攻击力 STenemy,防 御力 DEenemy。且所有怪物的属性都相同。 一旦走到怪物格,遭遇战将开始。扶苏一定会打死怪物,怪物对炮姐造成的伤害为 )),1m ax( ),1m ax( ,1m ax( my enemy enemym y enemy DE ST DES T HP         其中 ) ,(m ax b a 代表取 a 和 b 的最大值;  x 的值为不小于 x 的最小整数;下标为 enemy 的参数代表怪物的参数,下标为 my 的参数代表炮姐的参数 你会收到 q 次操作,每次操作要么是一次查询,要么是一次移动。 对于移动,你会再获得一个数字参数,这个参数只可能是 1/2/3/4 其中的一个,代表 炮姐向地图的 左/右/上/下 移动。
【输入格式】 输入文件名为 mzq.in。 输入文件中有且仅有一组数据,第一行为两个正整数 n 和 m,代表地图的大小 下面 n 行,每行 m 个字符,描述机关道的地图 下面一行有三个正整数,分别代表HPenemy,STenemy,DEenemy 下面一行有两个整数 x,y,代表炮姐初始在 第 x 行第 y 列出发。如果出发点有怪 物,不发生战斗,如果有道具,不会将其捡拾。
下面一行给出两个正整数,代表炮姐初始的 ST 和 DE。 下面一行给出一个整数 q,代表操作个数 以下q行,每行首先有一个数字,如果是 1,则代表一次查询。否则数字一定是 2, 代表炮姐的一次移动,一个空格后会给出一个数字,作为移动的参数。
【输出格式】 输出文件名为 mzq.out。 对于每个查询,输出一行三个用空格隔开的整数,代表炮姐损失的血量 HP,当前 的攻击力 ST,以及当前的防御力 DE
【输入输出样例 1】

5 5

MMMMM

RRRRR

QQQQQ

YYYYY

.....

5 5 5

5 1

10 10

8

2 3

1

2 3

2 3

2 3

1

2 2

1


一道模拟水题

代码:

#include <cstdio>
#ifdef ONLINE_JUDGE
#define freopen(a, b, c)
#endif
#define rg register
#define ci const int
#define cl const long long

typedef long long int ll;

namespace IPT {
    const int L = 1000000;
    char buf[L], *front=buf, *end=buf;
    char GetChar() {
        if (front == end) {
            end = buf + fread(front = buf, 1, L, stdin);
            if (front == end) return -1;
        }
        return *(front++);
    }
}

template <typename T>
inline void qr(T &x) {
    rg char ch = IPT::GetChar(), lst = ' ';
    while ((ch > '9') || (ch < '0')) lst = ch, ch=IPT::GetChar();
    while ((ch >= '0') && (ch <= '9')) x = (x << 1) + (x << 3) + (ch ^ 48), ch = IPT::GetChar();
    if (lst == '-') x = -x;
}

template <typename T>
inline void ReadDb(T &x) {
    rg char ch = IPT::GetChar(), lst = ' ';
    while ((ch > '9') || (ch < '0')) lst = ch, ch = IPT::GetChar();
    while ((ch >= '0') && (ch <= '9')) x = x * 10 + (ch ^ 48), ch = IPT::GetChar();
    if (ch == '.') {
        ch = IPT::GetChar();
        double base = 1;
        while ((ch >= '0') && (ch <= '9')) x += (ch ^ 48) * ((base *= 0.1)), ch = IPT::GetChar();
    }
    if (lst == '-') x = -x;
}

namespace OPT {
    char buf[120];
}

template <typename T>
inline void qw(T x, const char aft, const bool pt) {
    if (x < 0) {x = -x, putchar('-');}
    rg int top=0;
    do {OPT::buf[++top] = x % 10 + '0';} while (x /= 10);
    while (top) putchar(OPT::buf[top--]);
    if (pt) putchar(aft);
}

const int maxn = 1000010;
const int maxm = 2000010;
const int MOD = 100000007;

struct Edge {
    int to, nxt;
};
Edge edge[maxm]; int hd[maxn], ecnt = 1;
inline void cont(ci from, ci to) {
    Edge &e = edge[++ecnt];
    e.to = to; e.nxt = hd[from]; hd[from] = ecnt;
}

int n, t;
int MU[maxn], frog[maxn], gorf[maxn];

void reading();
void dfs(ci, ci);

int main() {
    freopen("1.in", "r", stdin);
    qr(n); qr(t);
    if (t) {
        for (rg int i = 1; i <= n; ++i) MU[i] = i;
    } else {
        for (rg int i = 1; i <= n; ++i) MU[i] = 1;
    }
    reading();
    dfs(1, 0); qw(frog[1], '
', true);
    return 0;
}

void reading() {
    int a, b;
    for (rg int i = 1; i < n; ++i) {
        a = b = 0; qr(a); qr(b);
        cont(a, b); cont(b, a);
    }
}

void dfs(ci u, ci pree) {
    for (int i = hd[u]; i; i = edge[i].nxt) if (i != pree) {
        int &to = edge[i].to;
        dfs(to, i ^ 1);
        frog[u] = (1ll * frog[to] * gorf[u] % MOD + 1ll * frog[u] * gorf[to] % MOD + frog[to] + frog[u]) % MOD;
        gorf[u] = (1ll * gorf[u] * gorf[to] % MOD + gorf[to] + gorf[u]) % MOD;
    }
    frog[u] = (frog[u] + MU[u]) % MOD;
    gorf[u] = (gorf[u] + 1) % MOD;
}

完结

原文地址:https://www.cnblogs.com/lbssxz/p/11073042.html