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\n", tt, -km());
}
return 0;
}
HDU-3523 Image copy detection的更多相关文章
- HDU 3523 Image copy detection(KM最大匹配)
HDU 3523 Image copy detection 题目链接 题意:这题事实上题意读懂就简单了,说白了就是1-n放到1-n列,每列的值为每列上数字和该数字的差的绝对值,然后求总和最小 思路:就 ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- hdu图论题目分类
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- HDU图论题单
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- 【转】KM匹配题集
转自:http://blog.csdn.net/shahdza/article/details/7779324 [HDU]2255 奔小康赚大钱 模板题★1533 Going Home 模板题★242 ...
- ### Paper about Event Detection
Paper about Event Detection. #@author: gr #@date: 2014-03-15 #@email: forgerui@gmail.com 看一些相关的论文. 1 ...
- 【HDOJ图论题集】【转】
=============================以下是最小生成树+并查集====================================== [HDU] How Many Table ...
- {ICIP2014}{收录论文列表}
This article come from HEREARS-L1: Learning Tuesday 10:30–12:30; Oral Session; Room: Leonard de Vinc ...
- Latex笔记(参考文献) 分类: LaTex 2014-11-08 17:41 239人阅读 评论(0) 收藏
当你用LaTeX来写文档,在管理参考文献时,你可能会用到bibtex, 也许你会嫌麻烦,会选择用 \begin{thebibliography}{10} \bibitem xxxx \bibitem ...
随机推荐
- [uestc oj]H - 邱老师选妹子
H - 邱老师选妹子 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submi ...
- codeforce Gym 100418K Cards (概率,数学)
题意:麦田的故事,n张牌,取x张牌,记住前x张牌最大的值m,继续往后取,遇到第一张比m大的牌就停下来.求一个x使得最后的牌在整副牌里是最大的期望最大. 假设最大的牌是A,A在各种位置出现的概率就是相等 ...
- 【转】json格式化、高亮库jsonFormater
http://leo108.com/pid-1996.asp JsonFormater 基于jQuery的json格式化.高亮库 核心代码参考天马行空工作室,本人只做了模块化和一些代码优化. demo ...
- USACO08FEB Hotel
题目传送门 线段树维护区间 线段树结构体 struct zzz{ int l,r,mi; //l为以左端点的为起点的最长子串 //r为以右端点为终点的最长子串 //mi是区间内部的最长子串 }tree ...
- cesium 基于天地图服务 完成底图标注渲染加切换
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- centOS下lnamp安装
首先安装apache,mysql ,最后安装php 1>apache安装 安装:yum install -y httpd 运行:/bin/systemctl start httpd.servic ...
- CentOS7 安装操作命令
#timedatectl set-timezone Asia/Shanghai 关闭SELinux vi /etc/sysconfig/selinux #SELINUX=enforcing SELIN ...
- 关于上传文件 非ajax提交 得到后台数据问题
<form name="configForm" id="configForm" method="post" action=" ...
- pandas-Notes1
#coding = utf-8 import pandas as pd import numpy as np import matplotlib as plt # series, like vecto ...
- LeetCode(217)Contains Duplicate
题目 Given an array of integers, find if the array contains any duplicates. Your function should retur ...