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
    **************************************
  • 相关阅读:
    上拉、下拉无限滚动组件-pc端
    elementui 表格应用1:多选+搜索框+保持选中状态
    uniapp初识笔记3
    uniapp 动态获取接口域名
    uniapp初识笔记2
    uniapp上传图片、视频到oss
    uniapp初识笔记
    vue登录页作为modal全局使用
    vue hash模式下微信分享,实现参数传递
    Vscode以管理员身份运行powershell
  • 原文地址:https://www.cnblogs.com/Wurq/p/3750276.html
Copyright © 2011-2022 走看看