zoukankan      html  css  js  c++  java
  • GYM 101673E(暴搜预处理)

    1.不会超过500个不同的串……
    2.样例没给has到has是怎么样的,实测是true。
    3.记忆化别剪错枝就好,嘤嘤嘤……

    const int maxn = 505 + 5;
    int n, m, tot;
    string s, op, t;
    bool can[maxn][maxn][2], used[maxn][2];
    map<string, int> id;
    
    void GetId(string s) {
    	if (!id[s])	id[s] = ++tot;
    }
    
    void dfs(int f, int cur, int op) {
    	if (used[cur][op])	return;
    	used[cur][op] = can[f][cur][op] = 1;
    
    	rep(i, 1, tot) {
    		if (can[cur][i][0])	dfs(f, i, op);
    		if (can[cur][i][1])	dfs(f, i, 1);
    	}
    }
    
    int main() {
    	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    	cin >> n >> m;
    	rep(i, 1, n) {
    		cin >> s >> op >> t;
    		GetId(s), GetId(t);
    		can[id[s]][id[t]][op[0] != 'i'] = 1;
    	}
    
    	rep(i, 1, tot) {
    		init(used, 0);
    		dfs(i, i, 0);
    	}
    
    	rep(i, 1, m) {
    		cin >> s >> op >> t;
    		cout << "Query " << i << ": ";
    		cout << (can[id[s]][id[t]][op[0] != 'i'] ? "true" : "false") << endl;
    	}
    
    	return 0;
    }
    
  • 相关阅读:
    HDU 5438 Ponds
    [HNOI2013]比赛
    [HNOI2009]最小圈
    【模板】高斯消元法
    控制公司 Controlling Companies
    sdut 2878 圆圈
    滑雪
    [ZJOI2010]排列计数
    [HNOI2003]激光炸弹
    [BZOJ 3732]Network
  • 原文地址:https://www.cnblogs.com/AlphaWA/p/10671526.html
Copyright © 2011-2022 走看看