zoukankan      html  css  js  c++  java
  • 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;
    }
    

      

  • 相关阅读:
    004 RequestMappingHandlerMapping
    003 HandlerMapping
    002 环境配置
    001 springmvc概述
    011 使用AOP操作注解
    010 连接点信息
    009 通知类型
    一台服务器的IIS绑定多个域名
    程序包需要 NuGet 客户端版本“2.12”或更高版本,但当前的 NuGet 版本为“2.8.50313.46”
    通过ping 主机名,或者主机名对应的IP地址
  • 原文地址:https://www.cnblogs.com/NanoApe/p/4382127.html
Copyright © 2011-2022 走看看