zoukankan      html  css  js  c++  java
  • Pet

    Pet

    Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
    Total Submission(s) : 28   Accepted Submission(s) : 9
    Problem Description
    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.
     
    Input
    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("%d
    ",sign);
    23     }
    24 
    25     return 0;
    26 }
    View Code
    转载请备注:
    **************************************
    * 作者: Wurq
    * 博客: https://www.cnblogs.com/Wurq/
    * Gitee: https://gitee.com/wurq
    **************************************
  • 相关阅读:
    day 30 粘包 自定义报头
    day29 网络基础之网络协议和通信
    day28 面向对象的进阶 反射 和类的内置方法
    day 27 模块和包 面向对象的复习
    CGI,FastCGI,PHP-CGI和PHP-FPM的区别
    跨平台的移动应用开发引擎CrossApp简介
    element-ui组件中的select等的change事件中传递自定义参数
    关于setInterval和setTImeout中的this指向问题
    懒加载和预加载的区别
    vueX的五个核心属性
  • 原文地址:https://www.cnblogs.com/Wurq/p/3750276.html
Copyright © 2011-2022 走看看