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 }
  • 相关阅读:
    redis单机主从搭建
    zabbix监控rds
    zabbix_server表面启动成功,但是没有进程
    sysbench压测mysql
    使用gnuplot对tpcc-mysql压测结果生成图表
    tpcc-mysql的使用
    tpcc-mysql安装
    鼠标点击烟花爆炸效果
    css3背景自动变色代码
    js实现文本输入框的特效
  • 原文地址:https://www.cnblogs.com/Deribs4/p/4779520.html
Copyright © 2011-2022 走看看