zoukankan      html  css  js  c++  java
  • King of Karaoke

    King of Karaoke
    Time Limit: 1 Second Memory Limit: 65536 KB
    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<bits/stdc++.h>
    
    using namespace std;
    int a[1000005];
    int b[1000005];
    vector<int> str;
    map<int,int> mp;
    int main()
    {
        int t,n,num;
        cin>>t;
        while(t--){
            int f=1;
            cin>>n;
            mp.clear();
            for(int i=0;i<n;i++){
                cin>>a[i];
            }
            for(int i=0;i<n;i++){
                cin>>b[i];
            }
            for(int i=0;i<n;i++){
                if(a[i]!=b[i])  f=0;
    
            }
            if(f) cout<<n<<endl;
            if(!f){
            for(int i=0;i<n;i++){
                mp[b[i]-a[i]]++; //map里面int可以放负数作为value-key
            }
            num=0;
            int Max=0;
            for(map<int,int>::iterator it = mp.begin();it!=mp.end();it++)
                if(it->second > num)
                {
                    num = it->second;
                }
                cout<<num<<endl;
           }
        }
    
    }
    /*
    sort(v.begin(),v.end(),less<int>());
            num=v[0];
            int count=1,min_num=v[0],min_count=1;
            for(i=1;i<N-1;i++)
            {
                if(v[i]>v[i-1])
                {
                    count=1;
                    if(count>min_count)
                       min_num=v[i];
                }
                else if(v[i]==v[i-1])
                {
                    count++;
                    if(count>min_count)
                    {
                        min_count=count;
                        min_num=v[i];
                    }
                }
            }
    
            if(v[N-1]==min_num)
                min_count++;
    
            cout<<min_num<<min_count<<endl;
    
            /*
            sort(v.begin(),v.end());
            int Max=0,num=1,value=v[0],pre=v[0];
            int cur;
            //-1 -1 -1 2
            for(int i=1;i<v.size();i++){
                cur=v[i];
                if(cur==pre) num++;
                else{
                    if(num>Max){
                        Max=num;
                        value=pre;
                    }
                    num=1;
                    pre=cur;
                }
            }
            cout<<Max<<endl;
            */
    
    
            /*
            int Max=1;
            for(int i=0;i<n;i++){
                num = count(v.begin(),v.end(),a[i]);
                Max=max(num,Max);
            }
            */
    
    
    
  • 相关阅读:
    python得到今天前的七天每天日期
    python 实现元组中的的数据按照list排序, python查询mysql得到的数据是元组格式,按照list格式对他们排序
    NoReverseMatch at /salesman/zhuce/ Reverse for '/zhuce/' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
    为什么springMVC和Mybatis逐渐流行起来了?
    图像的七个不变矩 可用于图像的匹配
    【可视化必备】大数据时代的可视化工具
    常用机器视觉工具----图像分析工具(blob分析)
    【转】七种常见阈值分割代码(Otsu、最大熵、迭代法、自适应阀值、手动、迭代法、基本全局阈值法)
    C#编写滤镜 图片色调取反效果(Invert)
    Bitmap四种属性
  • 原文地址:https://www.cnblogs.com/Roni-i/p/8970938.html
Copyright © 2011-2022 走看看