• 【Codeforces 670C】 Cinema


    【题目链接】

                  http://codeforces.com/contest/670/problem/C

    【算法】

               离散化

    【代码】

             

    #include<bits/stdc++.h>
    using namespace std;
    #define MAXN 200010
    
    int n,m,pos,mx = -1,nx = -1,len,i,rkb,rkc;
    int a[MAXN],b[MAXN],c[MAXN],s[MAXN<<2],tmp[MAXN<<2];
    
    template <typename T> inline void read(T &x)
    {
        int f = 1; x = 0;
        char c = getchar();
        for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
        for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
        x *= f;
    }
    template <typename T> inline void write(T x)
    {
        if (x < 0)
        {
            putchar('-');
            x = -x;
        }
        if (x > 9) write(x/10);
        putchar(x%10+'0');
    }
    template <typename T> inline void writeln(T x)
    {
        write(x);
        puts("");
    }
    
    int main() 
    {
            
            read(n);
            for (i = 1; i <= n; i++) 
            {
                    read(a[i]);
                    tmp[++len] = a[i];        
            }
            read(m);
            for (i = 1; i <= m; i++)
            {
                    read(b[i]);
                    tmp[++len] = b[i];
            }
            for (i = 1; i <= m; i++)
            {
                    read(c[i]);
                    tmp[++len] = c[i];
            }
            sort(tmp+1,tmp+n+2*m+1);
            len = unique(tmp+1,tmp+n+2*m+1) - tmp;
            for (i = 1; i <= n; i++) s[lower_bound(tmp+1,tmp+len+1,a[i])-tmp]++; 
            for (i = 1; i <= m; i++)
            {
                    rkb = lower_bound(tmp+1,tmp+len+1,b[i]) - tmp;
                    rkc = lower_bound(tmp+1,tmp+len+1,c[i]) - tmp;
                    if (s[rkb] > mx) 
                    {
                            pos = i;
                            mx = s[rkb];
                            nx = s[rkc];        
                    }    else if (s[rkb] == mx && s[rkc] > nx) 
                    {
                            pos = i;
                            nx = s[rkc];
                    }
            }
            writeln(pos);
            
            return 0;
        
    }
  • 相关阅读:
    注意安全 保重身体
    抽象和接口的区别
    哪些设计模式最值得学习
    超级扫盲什么是设计模式?
    简单工厂、工厂方法和抽象工厂模式
    通过领域模型设计物流系统
    json过滤特殊字符
    数据库性能优化JOIN方法说明[转]
    策略模式
    观察者模式
  • 原文地址:https://www.cnblogs.com/evenbao/p/9235649.html
Copyright © 2020-2023  润新知