zoukankan      html  css  js  c++  java
  • [HDOJ5326]Work

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5326

    找一连串的下属,可以用递归。首先存好直接关系,接着暴搜打表再查即可。

     1 #include <cstdio>
     2 #include <cstdlib>
     3 #include <cstring>
     4 #include <algorithm>
     5 #include <iostream>
     6 #include <cmath>
     7 #include <cctype>
     8 #include <queue>
     9 #include <map>
    10 #include <set>
    11 #include <stack>
    12 #include <list>
    13 #include <vector>
    14 
    15 using namespace std;
    16 
    17 const int maxn = 1010;
    18 int n, k, x, y;
    19 int par[maxn];
    20 int G[maxn][maxn];
    21 
    22 void dfs(int x, int y) {
    23     for(int i = 1; i <= n; i++) {
    24         if(G[y][i]) {
    25             par[x]++;
    26             dfs(x, i);
    27         }
    28     }
    29 }
    30 
    31 int main() {
    32     // freopen("in", "r", stdin);
    33     while(~scanf("%d %d", &n, &k)) {
    34         memset(par, 0, sizeof(par));
    35         memset(G, 0, sizeof(G));
    36         int ans = 0;
    37         for(int i = 0; i < n - 1; i++) {
    38             scanf("%d %d", &x, &y);
    39             G[x][y] = 1;
    40         }
    41         for(int i = 1; i <= n; i++) {
    42             for(int j = 1; j <= n; j++) {
    43                 if(G[i][j]) {
    44                     par[i]++;
    45                     dfs(i, j);
    46                 }
    47             }
    48         }
    49         for(int i = 1; i <= n; i++) {
    50             if(par[i] == k) {
    51                 ans++;
    52             }
    53         }
    54         printf("%d
    ", ans);
    55     }
    56     return 0;
    57 }
  • 相关阅读:
    Hive 2.1.1安装配置
    vi / vim 删除以及其它命令
    『MySQL』时间戳转换
    update 中实现子查询
    hive lateral view 与 explode详解
    xpath定位方法详解
    Python int与string之间的转化
    ORM、SQLAchemy
    python bottle 简介
    python wsgi 简介
  • 原文地址:https://www.cnblogs.com/kirai/p/4781621.html
Copyright © 2011-2022 走看看