• HDU-3523 Image copy detection


    题意难懂。。。

    大意上说就是给m个排列P1,P2,P3...Pm,自己求个排列T使得T与Pi的各个数的绝对值差之和最小。

    其实也就是二分最小匹配了。。。。

    #include <cstdlib>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <fstream>
    #include <iostream>
    #include <cctype>
    #define rep(i, l, r) for(int i=l; i<=r; i++)
    #define clr(x, c) memset(x, c, sizeof(x))
    #define MAX 0x3fffffff
    #define N 123
    using namespace std;
    int read()
    {
    	int x=0; char ch=getchar();
    	while (!isdigit(ch)) ch=getchar();
    	while (isdigit(ch)) { x=x*10+ch-'0'; ch=getchar(); } 
    	return x;
    }
    
    int n, m, l[N], st[N], lx[N], ly[N], v[N][N], k[N][N];
    bool vx[N], vy[N];
    
    bool Find(int x)
    {
    	vx[x]=1;
    	rep(y, 1, n) if (!vy[y])
    	{
    		int a=lx[x]+ly[y]-v[x][y];
    		if (!a)
    		{
    			vy[y]=1; if (!l[y] || Find(l[y])) { l[y]=x; return 1; }
    		}
    		else st[y]=min(st[y], a);
    	}
    	return 0;
    }
    
    inline int km()
    {
    	clr(ly, 0); clr(l, 0); rep(i, 1, n) lx[i]=-MAX;
    	rep(i, 1, n) rep(j, 1, n) if (lx[i]<v[i][j]) lx[i]=v[i][j];
    	rep(i, 1, n)
    	{
    		rep(j, 1, n) st[j]=MAX;
    		while (1)
    		{
    			clr(vx, 0); clr(vy, 0);
    			if (Find(i)) break; int a=MAX;
    			rep(j, 1, n) if (!vy[j] && a>st[j]) a=st[j];
    			rep(j, 1, n) if (vx[j]) lx[j]-=a;
    			rep(j, 1, n) if (vy[j]) ly[j]+=a; else st[j]-=a;
    		}
    	}
    	int a=0;
    	rep(i, 1, n) a+=lx[i]+ly[i];
    	return a;
    }
    
    int main()
    {
    	int t=read(), tt=0; while (tt++<t)
    	{
    		n=read(); m=read(); clr(k, 0); clr(v, 0);
    		rep(i, 1, m) rep(j, 1, n) k[j][read()]++;
    		rep(i, 1, n) rep(j, 1, n) rep(o, 1, n) v[i][j]-=abs(o-j)*k[i][o];
    		printf("Case #%d: %d
    ", tt, -km());
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    github加速
    aardio类的例子
    aardio调用dll
    荔枝派nano例子
    我的书单
    架构设计之熔断设计
    【leetcode】两数之和
    K-近邻算法(KNN)
    CLion之C++框架篇-优化开源框架,引入curl,实现get方式获取资源(四)
    CLion之C++框架篇-优化框架,引入boost(三)
  • 原文地址:https://www.cnblogs.com/NanoApe/p/4382127.html
Copyright © 2020-2023  润新知