zoukankan      html  css  js  c++  java
  • (TOJ3114){A}∩{B}

    描述

    Given two integer sets A and B sorted descendingly, you are asked to output the element count of A∩B.

    输入

    Standard input will contain multiple test cases. The first line of the input is a single integrate T (1 <= T <= 50) which is the number of test cases. then T consecutive test cases followed. In each test case, there has four lines. The first line contains the element count N(1<=N<=100000) for the first set. The second line contains N integers in the first set.
    The third line contains the element count M(1<=M<=100000) for the second set. The fourth line contains M integers in the second set.

    NOTE: there will be no duplicate elements in each sets and all the integers in each set have been sorted descendingly.

    输出

    For each test case in the input, there's only one line output that contains the element count of the intesection of the two sets.

    样例输入

    1
    5
    5 4 3 2 1
    4
    5 3 1 -1

    样例输出

    3
     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<ctype.h>
     4 #include<math.h>
     5 
     6 int a[100001],b[100001];
     7 
     8 void deal(int c[], int n, int d[], int m)
     9 {
    10     int i,j,flag;
    11     flag=i=j=0;
    12     while(i<n && j<m){
    13         if(c[i]<d[j]){j++;}
    14         else if(c[i]==d[j]){
    15             flag++;
    16             i++; j++;
    17         }else{
    18           i++;    
    19         }
    20     }
    21     printf("%d\n",flag);
    22 }
    23 
    24 void solve()
    25 {
    26     int T,n,m,i;
    27     scanf("%d",&T);
    28     while(T--){
    29         scanf("%d",&n);
    30         for(i=0; i<n; i++){
    31             scanf("%d",&a[i]);
    32         }
    33         scanf("%d",&m);
    34         for(i=0; i<m; i++){
    35             scanf("%d",&b[i]);
    36         }
    37         deal(a,n,b,m);        
    38     }
    39 }
    40 
    41 int main()
    42 {
    43     solve();
    44     return 0;
    45 }
     
  • 相关阅读:
    MAVEN flex
    计算几何--判断点是否在矩形里
    Maven copy方式列举
    配置 IntelliJ IDEA VM options
    解决访问StackOverFlow太慢的问题
    Android sdk manager 更新 5.0 太难了,终于解决
    为OS X增加环境变量
    激活老电脑的第二春:内存盘为Chrome浏览器做缓存
    Android启动外部应用的方法
    在Activities之间导航
  • 原文地址:https://www.cnblogs.com/xueda120/p/3095045.html
Copyright © 2011-2022 走看看