• HDU map统计两个数列固定差最大个数


    Problem A

    Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other)
    Total Submission(s) : 106   Accepted Submission(s) : 34
    Problem Description
    It's Karaoke time! DreamGrid is performing the song Powder Snow in the game King of Karaoke. The song performed by DreamGrid can be considered as an integer sequence $D_1, D_2, dots, D_n$, and the standard version of the song can be considered as another integer sequence $S_1, S_2, dots, S_n$. The score is the number of integers $i$ satisfying $1 le i le n$ and $S_i = D_i$.

    As a good tuner, DreamGrid can choose an integer $K$ (can be positive, 0, or negative) as his tune and add $K$ to every element in $D$. Can you help him maximize his score by choosing a proper tune?

    Input

    There are multiple test cases. The first line of the input contains an integer $T$ (about 100), indicating the number of test cases. For each test case:

    The first line contains one integer $n$ ($1 le n le 10^5$), indicating the length of the sequences $D$ and $S$.

    The second line contains $n$ integers $D_1, D_2, dots, D_n$ ($-10^5 le D_i le 10^5$), indicating the song performed by DreamGrid.

    The third line contains $n$ integers $S_1, S_2, dots, S_n$ ($-10^5 le S_i le 10^5$), indicating the standard version of the song.

    It's guaranteed that at most 5 test cases have $n > 100$.

    Output

    For each test case output one line containing one integer, indicating the maximum possible score.

    Sample Input

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

    Sample Output

    3
    1
    

    Hint

    For the first sample test case, DreamGrid can choose $K = 1$ and changes $D$ to ${2,3,4,5}$.

    For the second sample test case, no matter which $K$ DreamGrid chooses, he can only get at most 1 match.

    第一个数列各个位上的数字加上一个k可以得到第二个数列

    问最多有多少个数可以通过加上数字k等于第二个数列

    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cmath>
    #include <cstdio>
    #include <map>
    
    using namespace std ; 
    
    #define maxn 1100000
    int num1[maxn] , num2[maxn] , num[maxn] ; 
    int t ; 
    int n ; 
    map<int,int> mp ; 
    // 数据太多而且不方便枚举 数字 k 所以使用map
    int main(){
    
        cin >> t ; 
    
        while(t--){
            cin >> n ; 
            mp.clear() ; 
            for(int i=1 ; i<=n ; i++){
                cin >> num1[i] ; 
            }
            for(int i=1 ; i<=n ; i++){
                cin >> num2[i] ; 
            }
    
            for(int i=1 ; i<=n ; i++){
                mp[num1[i]-num2[i]] ++ ; 
            }
            int result = 0 ; 
            // 遍历map
            for(map<int,int>::iterator item = mp.begin();item!=mp.end() ;item++){
                if(item->second > result){
                    result = item->second ; 
                }
            }
            cout << result << endl ; 
        }
        return 0 ; 
    }
     
  • 相关阅读:
    HTML <form> 标签的 method 属性(20161028)
    PHP数据访问增删查(20161028)
    PHP数据访问基础知识(20161028)
    java代理机制
    java 模拟实现消费者和生产者问题
    Single Number II
    从1到1000中随机取出900个不重复的随机数
    取苹果方式总数
    Net-SNMP(V3协议)安装配置笔记(CentOS 5.2)(转)
    单例模式
  • 原文地址:https://www.cnblogs.com/yi-ye-zhi-qiu/p/9064873.html
Copyright © 2020-2023  润新知