紫皮,各种,非原创

树状数组在我的理解就是在决策过程中具有层次关系,像是树一样,具有上下级关系或者上级对上级一定程度的限制条件

 uva 12186

工人的请愿书

下属中不小于 T% 的人签字时会签字递给上级,问至少需要多少人签字才能传给老板

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>

const int MAXN = 100000+ 10;
const double ESP = 10e-8;
const double Pi = atan(1.0) * 4;
const int INF = 0xffffff;
const int MOD = 2012;
typedef long long LL;
using namespace std;
vector<int>sons[MAXN];
int n,T;
int dp(int u){
    if(sons[u].empty()){
        return 1;
    }
    int k = sons[u].size();
    vector<int>d;
    for(int i = 0;i < k;i++){
        d.push_back(dp(sons[u][i]));
    }
    sort(d.begin(),d.end());
    int c = (k*T - 1) / 100+ 1;
    int ans = 0;
    for(int i = 0;i < c;i++){
        ans += d[i];
    }
    return ans;
}
int main(){
    //freopen("input.txt","r",stdin);

    while(~scanf("%d%d",&n,&T)){
        if(!n && !T){
            break;
        }
        for(int i = 0;i <= n;i++){
            sons[i].clear();
        }
        for(int i = 1;i <= n;i++){
            int a;
            scanf("%d",&a);
            sons[a].push_back(i);
        }
        printf("%d\n",dp(0));
    }
    return 0;
}
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-01
  • 2021-05-28
  • 2022-02-18
  • 2021-11-03
  • 2021-05-31
  • 2022-12-23
猜你喜欢
  • 2022-01-07
  • 2021-10-05
  • 2021-07-15
  • 2022-02-27
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案