SGU 242 Student’s Morning

二分图匹配/网络流

把每个学校拆成两个点中间连一条容量下界为2的边,然后求可行流就行了。由于问题特殊,可以用二分图匹配来解决:把每个学校拆成两个点,如果一个学生愿意去一个学校,将这个学生和这个学校拆成的两个点各连一条边。利用匈牙利算法求二分图最大匹配,如果最大匹配数恰好为2k则有解,按照匹配方案输出即可,否则无解。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
 
using namespace std;
 
struct edge
{
	int v;
	edge *next;
	edge(int v,edge *next):v(v),next(next) {}
} *e[222];
int match[222];
bool u[222];
 
bool findAugmentPath(int v)
{
	for(edge *t=e[v];t;t=t->next)
		if(!u[t->v])
		{
			u[t->v]=true;
			if(!match[t->v]||findAugmentPath(match[t->v]))
			{
				match[t->v]=v;
				return true;
			}
		}
	return false;
}
 
int main()
{
	int n,k,t,p;
	scanf("%d%d",&n,&k);
	if(k*2>n)
	{
		puts("NO");
		return 0;
	}
	for(int i=1;i<=n;++i)
		for(scanf("%d",&t);t;--t)
		{
			scanf("%d",&p);
			e[i]=new edge(p,e[i]);
			e[i]=new edge(k+p,e[i]);
		}
	int total=0;
	for(int i=1;i<=n;++i)
	{
		memset(u,false,sizeof(u));
		if(findAugmentPath(i)) ++total;
	}
	if(total==(k<<1))
	{
		puts("YES");
		for(int i=1;i<=k;++i) printf("2 %d %d\n",match[i],match[k+i]);
	}
	else puts("NO");
	return 0;
}

Shawn Xu 许烁…

你可知道我在facebook你的墙上写下了如下这段话
It all came as a stunning shock to me. You just passed away, leaving so many people and things behind. I’ve never expressed my appreciation of you, but now I want you to know, and I’m sure you will know, that I’ve always been thinking highly of you. There are many, as you surely know it, people who love you so much and you, in turn, love each and everyone of them. I don’t reckon I’m able to be counted as your close friend, but I can’t really express my grief in words. There are so many people who know and care more about you. Love has power beyond death. With so many love, yours as well as others, in your heart, you may smile at the other end of the world. From my point of view at the very least, you are Master of Death…

细细想来,虽然从初中我与你相识,但我们真正相处的时间实在是太短了。我清楚记得你穿着制服手拿照相机的身影,我清楚记得初三时我参加信息学奥赛吉林省队选拔赛时你在机房门外关切的问我成绩时的面庞,我清楚记得我存你手机号时你特意强调你名字中的“烁”不是硕大的“硕”…

可你分明是一个硕大的人,不仅是你的外表,你总是那样乐观积极,好像世界上没有什么事能够压倒你硕大的身躯…但是…我真的不知道该把你的悲剧归因于或者归咎于什么…

生命是如此脆弱,如此易逝。我们这些仍然可以享受生命的幸运的人真的应该放慢生活匆忙的脚步,时常停下来去闻路边玫瑰的花香,时常停下来去感受大家对自己的爱,时常停下来去把爱的种子播撒…

TopCoder SRM 432 Summary

LampsGrid
枚举(思维难度大)
每次操作改变一整列的状态,所以如果初始时某两行状态相同,那么经过任意次操作后这两行的状态仍然相同;如果初始时某两行状态不相同,那么经过任意次操作后这两行的状态仍然不相同。枚举每一行,考虑能否把它通过K次操作变为全亮,如果能的话再数一数有多少行和这一行初始状态相同,它们也能通过同样的K次操作变为全亮。找出能变为全亮的且与之状态相同的行数最多的行即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <cmath>
#include <ctime>
#include <iostream>
#include <sstream>
#include <map>
#include <algorithm>
#include <string>
#include <vector>
 
using namespace std;
 
class LampsGrid
{
public:
	int mostLit(vector <string> initial, int K)
	{
		int ans=0;
		for(int i=0;i<initial.size();++i)
		{
			int num=0;
			for(int j=0;j<initial[i].size();++j) num+=initial[i][j]=='0';
			if(num>K||(K-num)%2) continue;
			num=0;
			for(int j=0;j<initial.size();++j) num+=initial[i]==initial[j];
			ans=max(ans,num);
		}
		return ans;
	}
};

NOI2009训练计划

新知学习:([]内为可选)
1、数据结构:后缀数组、[Splay]、Trie图、块状链表(实现)
2、字符串处理:扩展KMP、有限状态自动机
3、网络流模型:有上下界的最大流、最小费用最大流(简洁高效实现)
4、动态规划:四边形不等式优化、基于连通性的状态压缩动态规划

温故知新:
1、数据结构:递归Treap
2、网络流模型:Dinic、SAP
3、动态规划:斜率优化动态规划

题海战术:
1、USACO Contest 2006-2009年的全部金组题目(1-2套/周)
2、TopCoder SRM Divion 1从最近的开始(1-3道/天)
3、SPOJ、SGU、URAL上决不做简单题,只有特别需要时才能做

待修改…