【BZOJ 4625】[BeiJing2016] 水晶

题目传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4625
数据生成器:http://paste.ubuntu.com/23154162/

这个题目网上为什么搜不到题解QAQ
那我就来撸一份题解吧 = ̄ω ̄=

我们将六边形按照 (x+y+z)%3 == 0/1/2 来分类(染色)
不难发现,会变成这个样子:
486456445
之后,我们发现:两种共振一定是三个不同颜色的点产生的
于是把两种共振合起来考虑
因为我们必须任意三个中至少删一个,于是考虑最小割模型
将%3=1的点和S连一起,%3=2的和T连一起,%3=0的拆成两个点
现在产生共振的话,就连在一起。
这样的话,刚好符合题目的要求,于是跑一跑Dinic即可

#include<bits/stdc++.h>
#define LL long long
using namespace std;

const int N = 500000+9;
const int M = 1000000+9;
const int SGZ = 4100+9;
const int INF = 100000000;

int n,mat[SGZ][SGZ],idx[SGZ][SGZ],S,T,vout;
int nxt[M],head[N],to[M],flow[M],dis[N],cur[N];
struct Point{int x,y,t,c;}p[N];
queue<int> que;

inline bool cmp(const Point &A, const Point &B) {return A.x == B.x && A.y == B.y;}
inline bool CMP(const Point &A, const Point &B) {return A.x < B.x || (A.x == B.x && A.y < B.y);}

inline int read(){
	char c=getchar(); int ret=0,f=1;
	while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while (c<='9'&&c>='0') {ret=ret*10+c-'0';c=getchar();}
	return ret*f;
}

inline bool BFS(){
	memset(dis,-1,sizeof(dis));
	que.push(S); dis[S] = 0;
	
	while (!que.empty()) {
		int w = que.front(); que.pop(); 
		for (int i=head[w];i;i=nxt[i]) if (flow[i] && !~dis[to[i]]) 
			dis[to[i]] = dis[w] + 1, que.push(to[i]);
	}
	return ~dis[T];
}

int DFS(int w, int f) {
	if (w == T) return f;
	else {
		int ret = 0;
		for (int &i=cur[w];i;i=nxt[i]) if (flow[i] && dis[to[i]] == dis[w] + 1) {
			int tmp = DFS(to[i], min(f,flow[i]));
			flow[i] -= tmp; flow[i^1] += tmp;
			f -= tmp; ret += tmp;
			if (!f)	break;		
		} 
		return ret;
	}
}	

inline int Dinic(){
	int ret = 0;
	while (BFS()) {
		memcpy(cur,head,sizeof(head));
		ret += DFS(S,INF);
	} return ret;
}

inline void Add_Edge(int u, int v, int f){
	static int T = 1;
	to[++T] = v; nxt[T] = head[u]; head[u] = T; flow[T] = f;
	to[++T] = u; nxt[T] = head[v]; head[v] = T; flow[T] = 0;
}

int main(){
	n = read();
	for (int i=1,x,y,z,c;i<=n;i++) {
		x = read(); y = read(); z = read(); c = read(); 
		x += 2001 - z; y += 2001 - z; p[i].t = (x+y) % 3;  
		c *= ((x+y)%3)?10:11;	mat[x][y] += c; vout += c;
		p[i].x = x; p[i].y = y;
	} 
	sort(p+1,p+1+n,CMP); 
	n = unique(p+1,p+1+n,cmp) - p - 1; 
	S = n*2 + 1, T = n*2 + 2;
	for (int i=1;i<=n;i++) idx[p[i].x][p[i].y] = i, p[i].c = mat[p[i].x][p[i].y];
	for (int i=1;i<=n;i++) 
		if (p[i].t == 1) Add_Edge(S,i,p[i].c);
		else if (p[i].t == 2) Add_Edge(i,T,p[i].c);
		else Add_Edge(i,i+n,p[i].c);
	for (int i=1,x,y;i<=n;i++) if (!p[i].t) {
		x = p[i].x; y = p[i].y;
		if (idx[x+1][y]) Add_Edge(idx[x+1][y],i,INF);
		if (idx[x][y+1]) Add_Edge(idx[x][y+1],i,INF);
		if (idx[x-1][y-1]) Add_Edge(idx[x-1][y-1],i,INF);
		if (idx[x+1][y+1]) Add_Edge(i+n,idx[x+1][y+1],INF);
		if (idx[x][y-1]) Add_Edge(i+n,idx[x][y-1],INF);
		if (idx[x-1][y]) Add_Edge(i+n,idx[x-1][y],INF); 
	}
	vout -= Dinic();
	cout<<vout/10<<'.'<<vout%10;
	return 0;
}

至于怎样如何很自然地想到这样构图
我也不知道
R}AML}}{T7C5Y2FLTM`R%54
已经问了YYY,但他还没有回我QAQ

—– UPD 2016.9.10 —–
YYY告诉我,这货不是很常见的构图?
来源于多米诺骨牌模型?

—– UPD 2016.9.13 —–
刚好看到YYY提到的那一类题目了
http://acm.hit.edu.cn/hoj/problem/view?id=2713

72 thoughts to “【BZOJ 4625】[BeiJing2016] 水晶”

  1. Howdy would you mind stating which blog platform you’re using?
    I’m looking to start my own blog soon but I’m having
    a difficult time deciding between BlogEngine/Wordpress/B2evolution and
    Drupal. The reason I ask is because your layout seems different then most blogs and I’m looking for something unique.
    P.S Sorry for getting off-topic but I had to ask!

  2. Hi! I know this is kinda off topic but I was wondering which blog
    platform are you using for this website? I’m getting sick and tired
    of WordPress because I’ve had problems with hackers and I’m looking at options for another platform.
    I would be awesome if you could point me in the direction of a good platform.

  3. Have you ever considered about adding a little bit more than just your articles?
    I mean, what you say is valuable and everything. But think about if you added
    some great pictures or videos to give your posts more, “pop”!

    Your content is excellent but with pics and videos,
    this website could certainly be one of the best in its field.
    Excellent blog!

  4. You can definitely see your enthusiasm in the article you write.
    The sector hopes for even more passionate writers such as
    you who are not afraid to say how they believe. At all
    times go after your heart.

  5. Hi, i read your blog occasionally and i own a similar one and
    i was just wondering if you get a lot of spam comments?

    If so how do you protect against it, any plugin or anything you can advise?
    I get so much lately it’s driving me crazy so any help is very much
    appreciated.

  6. of course like your web-site but you have to take a look at the spelling on several of your posts.

    A number of them are rife with spelling problems
    and I to find it very bothersome to inform the truth then again I’ll definitely come again again.

  7. I am now not certain the place you’re getting your information, however great topic.
    I needs to spend a while learning more or working out more.

    Thank you for fantastic info I was looking for this information for my mission. plenty of fish natalielise

  8. Thank you for every other great article. Where else may anyone
    get that kind of information in such a perfect means of
    writing? I’ve a presentation subsequent week, and I am on the search for such info.

  9. Undeniably believe that which you stated. Your favorite justification appeared to be on the
    net the easiest thing to be aware of. I say to
    you, I definitely get annoyed while people consider worries that they plainly do not
    know about. You managed to hit the nail upon the top and defined out the whole thing without having side effect , people can take a
    signal. Will likely be back to get more. Thanks

  10. I’m no longer positive the place you are getting
    your information, but great topic. I must spend a while studying much more or working out more.
    Thank you for magnificent information I was on the lookout for this info for my mission.

  11. Hey There. I discovered your weblog using msn. This
    is a really well written article. I’ll make sure to bookmark it and come back to read
    extra of your useful info. Thank you for the post.
    I will certainly comeback.

  12. This is really interesting, You are a very skilled blogger.
    I have joined your rss feed and look forward to seeking more of your excellent post.
    Also, I’ve shared your web site in my social
    networks!

  13. Hmm is anyone else experiencing problems with the images on this blog loading?

    I’m trying to find out if its a problem on my end or
    if it’s the blog. Any feed-back would be greatly appreciated.

  14. Hi just wanted to give you a quick heads up and let
    you know a few of the images aren’t loading correctly. I’m not sure why but
    I think its a linking issue. I’ve tried it in two different web browsers and both show the same outcome.

  15. My brother recommended I may like this blog. He used to be entirely right.
    This submit actually made my day. You can not believe just how so much time I had
    spent for this information! Thanks!

  16. whoah this weblog is great i like reading your articles.
    Keep up the great work! You know, lots of persons are looking round for this information, you can aid
    them greatly.

  17. My brother recommended I would possibly like this blog.

    He was totally right. This publish actually
    made my day. You can not believe simply how so much
    time I had spent for this info! Thank you!

  18. Magnificent beat ! I wish to apprentice while you amend your site,
    how could i subscribe for a weblog site? The account aided me a applicable deal.

    I had been tiny bit acquainted of this your broadcast provided vibrant transparent idea

  19. Today, I went to the beach with my children. I found a sea shell and gave it
    to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and screamed.
    There was a hermit crab inside and it pinched her ear.
    She never wants to go back! LoL I know this is entirely off topic but I had to tell
    someone!

  20. Hi, I think your website might be having browser compatibility issues.

    When I look at your blog site in Safari, it looks fine but when opening in Internet Explorer, it has some overlapping.
    I just wanted to give you a quick heads up! Other then that, great blog!

  21. Today, I went to the beach front with my kids. I found a sea shell and gave it to my 4 year old daughter and said
    “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and screamed.
    There was a hermit crab inside and it pinched her ear. She
    never wants to go back! LoL I know this is entirely off topic but I had to tell someone!

  22. I think everything said was actually very logical.

    However, consider this, what if you composed a catchier post title?
    I mean, I don’t wish to tell you how to run your blog, however
    suppose you added something that grabbed people’s attention? I mean 【BZOJ 4625】[BeiJing2016] 水晶 – Qizy'
    s Database is kinda vanilla. You could glance at Yahoo’s front page and watch how
    they write news titles to grab viewers to click. You
    might try adding a video or a picture or two to get
    people excited about everything’ve written. In my opinion, it could make your
    blog a little livelier.

  23. I will right away grasp your rss as I can’t find your e-mail
    subscription hyperlink or e-newsletter service. Do you have any?
    Kindly let me know so that I may just subscribe. Thanks.

  24. I think this is one of the most important info for me. And
    i am glad reading your article. But wanna remark on some general things, The web site style is ideal, the articles is really great :
    D. Good job, cheers

  25. Hi! I realize this is kind of off-topic however I had to ask.
    Does running a well-established website like yours take a large
    amount of work? I am completely new to running a blog but I do write in my diary
    everyday. I’d like to start a blog so I can easily share
    my own experience and views online. Please let me know if you have any kind of recommendations or tips for brand new
    aspiring bloggers. Thankyou!

  26. I’m really enjoying the design and layout of your website.

    It’s a very easy on the eyes which makes it much more enjoyable for me to come here and visit more often. Did you hire
    out a designer to create your theme? Superb work!

  27. Pretty nice post. I simply stumbled upon your blog and wished to
    say that I have really loved surfing around your weblog posts.
    After all I’ll be subscribing to your feed and I am hoping you write once more very soon!

  28. First of all I would like to say superb blog!
    I had a quick question in which I’d like to ask if you don’t mind.

    I was interested to find out how you center yourself and clear your
    thoughts before writing. I have had a tough time clearing my thoughts in getting my thoughts
    out there. I truly do take pleasure in writing however it just seems like the first 10 to 15 minutes are generally wasted just trying
    to figure out how to begin. Any recommendations or
    hints? Kudos!

Leave a Reply

Your email address will not be published. Required fields are marked *