zoukankan      html  css  js  c++  java
  • 1410

    1410 - Consistent Verdicts
    Time Limit: 5 second(s) Memory Limit: 32 MB

    In a 2D plane N persons are standing and each of them has a gun in his hand. The plane is so big that the persons can be considered as points and their locations are given as Cartesian coordinates. Each of the N persons fire the gun in his hand exactly once and no two of them fire at the same or similar time (the sound of two gun shots are never heard at the same time by anyone so no sound is missed due to concurrency). The hearing ability of all these persons is exactly same. That means if one person can hear a sound at distance R1, so can every other person and if one person cannot hear a sound at distance R2 the other N-1 persons cannot hear a sound at distance R2 as well.

     

    The N persons are numbered from 1 to N. After all the guns are fired, all of them are asked how many gun shots they have heard (not including their own shot) and they give their verdict. It is not possible for you to determine whether their verdicts are true but it is possible for you to judge if their verdicts are consistent. For example, look at the figure above. There are five persons and their coordinates are (1, 2), (3, 1), (5, 1), (6, 3) and (1, 5) and they are numbered as 1, 2, 3, 4 and 5 respectively. After all five of them have shot their guns, you ask them how many shots each of them have heard. Now if there response is 1, 1, 1, 2 and 1 respectively then you can represent it as (1, 1, 1, 2, 1). But this is an inconsistent verdict because if person 4 hears 2 shots then he must have heard the shot fired by person 2, then obviously person 2 must have heard the shot fired by person 1, 3 and 4 (person 1 and 3 are nearer to person 2 than person 4). But their opinions show that Person 2 says that he has heard only 1 shot. On the other hand (1, 2, 2, 1, 0) is a consistent verdict for this scenario so is (2, 2, 2, 1, 1). In this scenario (5, 5, 5, 4, 4) is not a consistent verdict because a person can hear at most 4 shots.

    Given the locations of N persons, your job is to find the total number of different consistent verdicts for that scenario. Two verdicts are different if opinion of at least one person is different.

    Input

    Input starts with an integer T (≤ 100), denoting the number of test cases.

    Each case starts with a line containing a positive integer N (1 ≤ N ≤ 700). Each of the next N lines contains two integers xi yi (0 ≤ xi, yi ≤ 30000)denoting a co-ordinate of a person. Assume that all the co-ordinates are distinct.

    Output

    For each case, print the case number and the total number of different consistent verdicts for the given scenario.

    Sample Input

    Output for Sample Input

    2

    3

    1 1

    2 2

    4 4

    2

    1 1

    5 5

    Case 1: 4

    Case 2: 2

    题解:

    题意就是n个人每个人听到枪响次数的方案,由于距离问题有的人可能听不到枪响;其实就是不同距离的个数

    代码:

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<algorithm>
     6 #include<set>
     7 using namespace std;
     8 set<double>st;
     9 const int MAXN=1e6;
    10 double c[MAXN];
    11 struct Node{
    12     int x,y;
    13 };
    14 Node dt[1010];
    15 double getd(Node a,Node b){
    16     int x=a.x-b.x,y=a.y-b.y;
    17     return sqrt(1.0*x*x+y*y);
    18 }
    19 int main(){
    20     int T,N,flot=0;
    21     scanf("%d",&T);
    22     while(T--){
    23         scanf("%d",&N);
    24         for(int i=0;i<N;i++)
    25         scanf("%d%d",&dt[i].x,&dt[i].y);
    26     //    st.clear();
    27         int k=0;
    28         for(int i=0;i<N;i++)
    29             for(int j=i+1;j<N;j++)
    30                 c[k++]=getd(dt[i],dt[j]);
    31                 //st.insert(getd(dt[i],dt[j]));
    32                 int ans=k;
    33                 sort(c,c+k);
    34             for(int i=1;i<k;i++)
    35                 if(c[i]==c[i-1])ans--;
    36         printf("Case %d: %d
    ",++flot,ans+1);
    37     }
    38     return 0;
    39 }
  • 相关阅读:
    程序员移居国外指南(1)-父母怎么办?
    【广州.NET社区线下活动】云定未来
    TDD/BDD和接口、基类、继承、依赖注入DI
    德国慕尼黑.NET俱乐部VS2019发布活动
    大湾区联动:广州深圳助力东莞.NET俱乐部首次线下活动
    .NET的未来-广州.NET俱乐部学生分会
    Belgrade Azure 2019-2-11活动感悟
    参观微软Serbia开发中心和Office365 2019-01-31活动感悟
    MySQL复制(二)--基于二进制日志文件(binlog)配置复制
    MySQL复制(一)--复制概述
  • 原文地址:https://www.cnblogs.com/handsomecui/p/4954028.html
Copyright © 2011-2022 走看看