zoukankan      html  css  js  c++  java
  • 「JLOI2012」树

    「JLOI2012」树

    传送门
    不得不说这题的数据是真的水。。。
    我们可以想到很明确的一条思路:枚举每一个点向根节点跳,知道路径和不小于 (s),恰好等于 (s) 就直接加答案。
    跳的过程可以用倍增搞,但是暴力跳也可以过(这棵树的高度比较友好啊)
    我只给了暴力的代码,倍增的懒得去写了。。。
    参考代码:

    /*--------------------------------
      Code name: B.cpp
      Author: The Ace Bee
      This code is made by The Ace Bee
    --------------------------------*/
    #include <cstdio>
    #define rg register
    #define file(x)									
    	freopen(x".in", "r", stdin);				
    	freopen(x".out", "w", stdout);
    const int $ = 100010;
    inline int read() {
    	int s = 0; bool f = false; char c = getchar();
    	while (c < '0' || c > '9') f |= (c == '-'), c = getchar();
    	while (c >= '0' && c <= '9') s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
    	return f ? -s : s;
    }
    int n, s, val[$], fa[$];
    inline int jump(int u) {
    	int tmp = 0;
    	for (; u && tmp < s; u = fa[u]) tmp += val[u];
    	return tmp == s;
    }
    int main() {
    //	file("B");
    	n = read(), s = read();
    	for (rg int i = 1; i <= n; ++i) val[i] = read();
    	for (rg int u, v, i = 1; i <= n - 1; ++i)
    		u = read(), v = read(), fa[v] = u;
    	int ans = 0;
    	for (rg int i = 1; i <= n; ++i) ans += jump(i);
    	printf("%d
    ", ans);
    	return 0;
    }
    
  • 相关阅读:
    chattr
    chage命令
    passwd命令
    usermod命令
    userdel命令
    useradd命令
    信息热词分析系统重构
    pandas数据清洗
    python 中mysql数据库的读写
    java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
  • 原文地址:https://www.cnblogs.com/zsbzsb/p/12246855.html
Copyright © 2011-2022 走看看