2018 ACM ICPC Asia Regional - Seoul B.Cosmetic Survey

Reference code

Topic

n n n customers,mmm kinds of makeup products, each customer will givemmA value for m cosmetics. This value represents the ranking of this cosmetic in his mind. The smaller the ranking, the more you like it. If this value is 0, it means you dislike this cosmetic the least (a value of 0 is interpreted as infinity)

Now define d (x, y) d(x,y)d(x,y ) meansxxx cosmetics andyyAmong y kinds of cosmetics, like thexxx number of cosmetics

Define a sequence C 1, C 2, C 3,…, C k C_1,C_2,C_3,\dots,C_kC1,C2,C3,,Ck,其中保证 d ( C i , C i + 1 ) > d ( C i + 1 , C i ) d(C_i,C_{i+1})>d(C_{i+1},C_i) d(Ci,Ci+1)>d(Ci+1,Ci) , and this path has a value (sequence value) representingd (C t, C t + 1), 1 ≤ t <kd(C_t,C_{t+1}),1\leq t<kd(Ct,Ct+1),1t<The minimum value of k .

定义 S ( x , y ) S(x,y) S(x,y ) , forall theabovesequencesC 1 = x C_1=xC1=x C k = y C_k=y Ck=y isxxx is the beginning,yyThe maximumvalueofthe sequence at the end of y

If for a cosmetic xxx来说的 S ( x , i ) ≥ S ( i , x ) , ( 1 ≤ i ≤ m , i ≠ x ) S(x,i)\ge S(i,x),(1\leq i\leq m,i\ne x) S(x,i)S(i,x),(1im,i=x ) iifor the above conditionsi are all established, then it is a "good" cosmetic.

Now find the numbers of all "good" cosmetics?

First find out d (i, j) d(i,j) violentlyd(i,j),然后floyd暴力求出 S ( i , j ) = m a x ( S ( i , j ) , m i n ( d ( i , k ) , d ( k , j ) ) ) S(i,j)=max(S(i,j),min(d(i,k),d(k,j))) S(i,j)=max(S(i,j),m i n ( d ( i ,k),d(k,j ) ) )
Finally, the violent comparison finds the answer.

#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<random>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=510;
int n,m;
int a[N][N],d[N][N];
int main()
{
    
    
    IO;
    int T=1;
    //cin>>T;
    while(T--)
    {
    
    
        cin>>m>>n;
        for(int i=1;i<=n;i++)   
            for(int j=1;j<=m;j++)
            {
    
    
                cin>>a[i][j];
                if(a[i][j]==0) a[i][j]=1e8;
            }
        for(int i=1;i<=m;i++)   
            for(int j=i+1;j<=m;j++)
            {
    
    
                for(int k=1;k<=n;k++)
                {
    
    
                    if(a[k][i]<a[k][j]) d[i][j]++;
                    if(a[k][i]>a[k][j]) d[j][i]++;
                }
                int x=d[i][j],y=d[j][i];
                if(x>=y) d[j][i]=0;
                if(y>=x) d[i][j]=0;
            }
        for(int k=1;k<=m;k++)   
            for(int i=1;i<=m;i++)
                for(int j=1;j<=m;j++)
                {
    
    
                    if(!d[i][k]||!d[k][j]) continue;
                    d[i][j]=max(d[i][j],min(d[i][k],d[k][j]));
                }
        vector<int> ans;
        for(int i=1;i<=m;i++)
        {
    
    
            bool ok=1;
            for(int j=1;j<=m;j++)
            {
    
    
                if(i==j) continue;
                if(d[i][j]<d[j][i]) ok=0;
            }
            if(ok) ans.push_back(i);
        }
        for(auto t:ans) cout<<t<<' ';
        cout<<'\n';
    }
    return 0;
}

Summary: First, you need to violently understand the meaning of the question

Guess you like

Origin blog.csdn.net/Fighting_Peter/article/details/110411849