首页 > 分享 > 寻找逃逸仓鼠的算法

寻找逃逸仓鼠的算法

One day, Lin Ji wake up in the morning and found that his pethamster escaped. He searched in the room but didn’t find the hamster. He tried to use some cheese to trap the hamster. He put the cheese trap in his room and waited for three days. Nothing but cockroaches was caught. He got the map of the school and foundthat there is no cyclic path and every location in the school can be reached from his room. The trap’s manual mention that the pet will always come back if it still in somewhere nearer than distance D. Your task is to help Lin Ji to find out how many possible locations the hamster may found given the map of the school. Assume that the hamster is still hiding in somewhere in the school and distance between each adjacent locations is always one distance unit.

The input contains multiple test cases. Thefirst line is a positive integer T (0<t<=10), div="" <="" n="" 0.="" location="" at="" always="" room="" ji’s="" lin="" map.="" adjacent="" y="" that="" meaning="" space,="" y(0<="x,y<N)," x="" map,="" descripts="" n-1lines="" following="" trap.="" distance="" affective="" d="" school="" in="" locations="" is="" space.="" single="" a="" by="" separated="" d(0<d<n),="" and="" (0<n<="100000)" integer="" positive="" two="" has="" line="" first="" cases,="" each="" for="" cases.="" test="" of="" number="" the="">

Output

For each test case, outputin a single line the number of possible locations in the school the hamster may be found.

Sample Input

1 10 2 0 1 0 2 0 3 1 4 1 5 2 6 3 7 4 8 6 9

Sample Output

2

Source

2013 ACM/ICPC Asia Regional Online —— Warmup

1 #include <stdio.h> 2 #include <string.h> 3 4 int main() 5 { 6 int T,i,j,head,last,sign,times,high,num[100005]; 7 scanf("%d",&T); 8 while(T--) 9 { 10 memset(num,0,sizeof(num)); 11 scanf("%d%d",&times,&high); 12 for(i=1;i<times;i++) 13 { 14 scanf("%d%d",&head,&last); 15 num[last]=num[head]+1; 16 } 17 for(i=0,sign=0;i<=last;i++) 18 { 19 if(num[i]>high) 20 sign++; 21 } 22 printf("%dn",sign); 23 } 24 25 return 0; 26 }

View Code

相关知识

寻找逃逸仓鼠的算法
宠物逃逸事故怎么处理
旅客将仓鼠带上飞机致全体旅客下机? 宠物逃逸引航班延误
蚁群算法+Dijkstra算法=二维路径规划,基于蚁群算法的机器人路径规划,matlab源码.rar资源
泗阳女子宠物蛇意外逃逸事件
看好你的鸟!鹦鹉外出逃逸问题研究
粒子群算法学习(PSO)
仓鼠饲养常见问题解析(解答您对仓鼠饲养的疑惑)
警惕!开车撞狗=肇事逃逸?
算法思想(二)——排序基础

网址: 寻找逃逸仓鼠的算法 https://m.mcbbbk.com/newsview1212670.html

所属分类:萌宠日常
上一篇: 英国男子把宠物放微波炉加热 被判
下一篇: 我也养了小仓鼠