zoukankan      html  css  js  c++  java
  • pat1063. Set Similarity (25)

    1063. Set Similarity (25)

    时间限制
    300 ms
    内存限制
    65536 kB
    代码长度限制
    16000 B
    判题程序
    Standard
    作者
    CHEN, Yue

    Given two sets of integers, the similarity of the sets is defined to be Nc/Nt*100%, where Nc is the number of distinct common numbers shared by the two sets, and Nt is the total number of distinct numbers in the two sets. Your job is to calculate the similarity of any given pair of sets.

    Input Specification:

    Each input file contains one test case. Each case first gives a positive integer N (<=50) which is the total number of sets. Then N lines follow, each gives a set with a positive M (<=104) and followed by M integers in the range [0, 109]. After the input of sets, a positive integer K (<=2000) is given, followed by K lines of queries. Each query gives a pair of set numbers (the sets are numbered from 1 to N). All the numbers in a line are separated by a space.

    Output Specification:

    For each query, print in one line the similarity of the sets, in the percentage form accurate up to 1 decimal place.

    Sample Input:
    3
    3 99 87 101
    4 87 101 5 87
    7 99 101 18 5 135 18 99
    2
    1 2
    1 3
    
    Sample Output:
    50.0%
    33.3%
    

    提交代码

     1 #include<cstdio>
     2 #include<stack>
     3 #include<cstring>
     4 #include<iostream>
     5 #include<stack>
     6 #include<set>
     7 #include<map>
     8 using namespace std;
     9 map<int,set<int> > ha;
    10 int main(){
    11     //freopen("D:\INPUT.txt","r",stdin);
    12     int n,m;
    13     scanf("%d",&n);
    14     int i,j,num;
    15     for(i=1;i<=n;i++){
    16         scanf("%d",&m);
    17         for(j=0;j<m;j++){
    18             scanf("%d",&num);
    19             ha[i].insert(num);
    20         }
    21     }
    22     /*for(i=1;i<=n;i++){
    23         cout<<"i:  "<<i<<endl;
    24         set<int>::iterator it;
    25         for(it=ha[i].begin();it!=ha[i].end();it++){
    26             cout<<*it<<endl;
    27         }
    28     }*/
    29     scanf("%d",&m);
    30     int a,b;
    31     set<int>::iterator it;
    32     for(i=0;i<m;i++){
    33         scanf("%d %d",&a,&b);
    34         int sum=0;
    35         for(it=ha[a].begin();it!=ha[a].end();it++){
    36             if(ha[b].count(*it)){
    37                 sum++;
    38             }
    39         }
    40         //cout<<sum<<" "<<ha[b].size()+ha[a].size()<<endl;
    41         printf("%.1lf%
    ",sum*1.0*100/(ha[b].size()+ha[a].size()-sum));
    42     }
    43     return 0;
    44 }
  • 相关阅读:
    首页调单个产品分类的推荐产品,最新产品和热卖商品
    ecshop模板<! TemplateBeginEditable name="左上角主区域" >用法
    复制DataTable数据到新DataTable
    定时任务时间与当前时间比较的方法
    批量删除文件夹下包含指定字段的文件
    SQL 字符串去除空格函数
    Javascript的IE和Firefox(火狐)兼容性的常用例子
    查询表某列的加权平均值
    Jquery实现页面定时跳转
    Date.parse Firefox返回Nan的解决办法
  • 原文地址:https://www.cnblogs.com/Deribs4/p/4779520.html
Copyright © 2011-2022 走看看