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
    **************************************
  • 相关阅读:
    LinQ表达式的一点点总结(二)select中新建对象
    给自己的博客添加分享到功能
    职场日记2上班第一天
    清楚屏幕右侧变化的数据Application.Current.Host.Settings.EnableFrameRateCounter = true;
    基于委托的异步
    C#中的装箱与拆箱
    关于java的初始化问题
    StreamReader类以及其方法ReadLine,Read,ReadToEnd的分析
    WP7的控件开发入门(二)
    单元测试的阶段性总结
  • 原文地址:https://www.cnblogs.com/Wurq/p/3750276.html
Copyright © 2011-2022 走看看