奶茶爱好者(贪心,二分图,)

英文预备:

second to none

conduct a milk tea festival

make many cups of milk tea

savour(savor)品味,细品,享用;体味,享受。

savor milk tea.

题目地址:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1011&cid=855

分析: 
bipartite( involving or made up of two separate parts ) graph:二分图
因此,二分图的表示为:G=(U,V,E)。or G=(U+V,E)。

如果|U|=|V|,即集合U和集合V的元素个数相等,该二分图称为“平衡二分图”(Balanced bipartite graph)。 

 

 

 

Hall’s marriage theorem:

 Go reading 《Recreational Mathematics Magazines》

Problems:The Mutilated(残缺的,破坏的) Chess Board

find an unexpected connection,and discover the true power of abstract mathematics while still seeing the concrete applications in action.

. Sometimes even classic puzzles can turn up something new and interesting.

a set of dominos,(多米诺骨牌)

 

解决: 

#include<bits/stdc++.h>
using namespace std;
int n;
//two arrays that integers in them 0<= element <=10^9
long long a[1<<20],b[1<<20];

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		//begin to build an imaginary bipartite graph.
		for(int i=0;i<n;i++) scanf("%lld%lld",a+i,b+i);
		
		//|U|==totu==accumulate(a,a+n,0ll).
		long long totu=accumulate(a,a+n,0ll);
		//|V|
		long long totv=accumulate(b,b+n,0ll);
		long long ans=min(totu,totv);
		//magic codes.
		//using Hall's marriage theorem.
		for(int i=0;i<n;i++) ans=min(ans,totu+totv-a[i]-b[i]);
		//all three cases can be computed in linear time. 
		printf("%lld\n",ans);
	}
	return 0;
}

  

 

 

 
 
 

 

posted @ 2019-08-15 13:24  龙龙666666  阅读(280)  评论(0编辑  收藏  举报