首页 > 其他分享 >Another Crisis UVA - 12186

Another Crisis UVA - 12186

时间:2023-04-14 15:36:07浏览次数:36  
标签:1.0 int tot dfs Another UVA include Crisis size

 

 

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int N=1e5+3;
int f[N],n,K;

 vector<int> g[N]; 
 void dfs(int x){
 	int b[N],tot; 
 	tot=0;
 	
 	if(g[x].size()==0){
 		f[x]=1; return;
 	}
 	for(auto y:g[x]){
 		dfs(y); b[++tot]=f[y];
 	}
 	sort(b+1,b+1+tot);
 	
 	int t=int(g[x].size()/100.0*K*1.0);
 	if(double(t)!=(double)(g[x].size()/100.0*K*1.0))
	t++;
	for(int i=1;i<=t;++i) f[x]+=b[i];
 }
 signed main(){
 	while(cin>>n>>K,n||K){
 		
 		for(int i=1;i<=n;i++){
 			int x; cin>>x; g[x].push_back(i);
 		}
 		dfs(0);
 		cout << f[0]<<endl;
 		for(int i=0;i<=n;i++) f[i]=0,g[i].clear();
 	}
 }
 
 
 

 

标签:1.0,int,tot,dfs,Another,UVA,include,Crisis,size
From: https://www.cnblogs.com/towboa/p/17318423.html

相关文章

  • UVa 10182 Bee Maja (规律&O(1)算法)
    10182-BeeMajaTimelimit:3.000seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1123Majaisabee.Shelivesinabeehivewiththousandsofotherbees.Thisbeehivecon......
  • Alibaba UVA - 1632
    在一条直线的同一个方向上有nn件珠宝,已知每件珠宝的位置,并且第ii件珠宝在Ti时刻消失,问将所有的珠宝收集起来最小耗时?搜集不耗时,移动需要耗时 类似区间dpf[i][j][2]#pragmaGCCoptimize(2)#include<iostream>usingnamespacestd;constintN=1e4+3......
  • uva 11082 A Plug for UNIX
     #include<iostream>#include<vector>#include<map>#include<queue>#include<cstring>usingnamespacestd;constintN=1e4+2,M=5e5;intn1,n2,n3,len;map<string,int>mp;map<int,int>A,B;constintin......
  • HDU 3306 Another kind of Fibonacci(矩阵快速幂)
    题目地址:HDU3306没什么智商的题目,只要把构造矩阵硬算出来就行。代码如下:#include<iostream>#include<cstdio>#include<string>#include<cstring>#include<stdlib.h>#include<math.h>#include<ctype.h>#include<queue>#include<......
  • Calling Circles UVA - 247
    如果两个人相互打电话(直接或间接),则说他们在同一个电话圈里。例如,a打给b,b打给c,c打给d,d打给a,则这4个人在同一个圈里;如果e打给f但f不打给e,则不能推出e和f在同一个电话圈里。输入n(n≤25)个人的m次电话,找出所有电话圈。人名只包含字母,不超过25个字符,且不重复 对于一个有向图,Flo......
  • UVa 10049 Self-describing Sequence (自描述序列&二分递推)
    10049-Self-describingSequenceTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=34&page=show_problem&problem=990SolomonGolomb's self­describingsequence  istheonlynon­decreas......
  • Shanghai 2006 / UVa 1382 Distant Galaxy (枚举&扫描&动态维护)
    1382-DistantGalaxyTimelimit:3.000seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=460&page=show_problem&problem=4128YouareobservingadistantgalaxyusingatelescopeabovetheAstronomyTower,......
  • UVa 514 Rails (water ver.)
    514-RailsTimelimit:3.000seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=455ThereisafamousrailwaystationinPopPushCity.Countrythereisincrediblyhilly.Thest......
  • UVa 11044 Searching for Nessy (water ver.)
    11044-SearchingforNessyTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=99&page=show_problem&problem=1985TheLochNessMonsterisamysteriousandunidentifiedanimalsaidtoinhabi......
  • UVa 846 Steps (数学)
    846-StepsTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=99&page=show_problem&problem=787Onestepsthroughintegerpointsofthestraightline.Thelengthofastepmustbenonnegat......