【BZOJ 3566】[SHOI2014] 概率充电器

相关链接

题目传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3566
神犇题解:https://blog.sengxian.com/solutions/bzoj-3566

解题报告

首先根据期望的线性,我们只需要求出每个元件有电的概率,之后相加就是答案
那么怎么求每个元件有电的概率呢?我们可以无脑点分
显然在$O(n)$的时间复杂度内搞一发树形$DP$就可以了

Code

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

const int N = 500009;
const int M = N << 1;

int n,head[N],nxt[M],to[M]; 
double up[N],down[N],cost[M],q[N],vout;

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 void AddEdge(int u, int v, int f) {
	static int E = 1; 
	cost[E+1] = cost[E+2] = f / 100.0;
	to[++E] = v; nxt[E] = head[u]; head[u] = E;
	to[++E] = u; nxt[E] = head[v]; head[v] = E;
}

void DFS1(int w, int f) {
	down[w] = 1 - q[w];
	for (int i=head[w];i;i=nxt[i]) {
		if (to[i] != f) {
			DFS1(to[i], w);
			down[w] *= down[to[i]] + (1 - down[to[i]]) * (1 - cost[i]);
		}
	}
}

void DFS2(int w, int f, double p) {
	vout += 1 - (up[w] = down[w] * p);
	for (int i=head[w];i;i=nxt[i]) {
		if (to[i] != f) {
			double tmp = p * down[w] / (down[to[i]] + (1 - down[to[i]]) * (1 - cost[i]));
			DFS2(to[i], w, tmp + (1 - tmp) * (1 - cost[i]));
		}
	}
}

int main() {
	n = read();
	for (int i=1,u,v;i<n;i++) {
		u = read(); v = read();
		AddEdge(u, v, read());
	}
	for (int i=1;i<=n;i++) q[i] = read() / 100.0;
	DFS1(1, 1);
	DFS2(1, 1, 1);
	printf("%.6lf\n",vout);
	return 0;
}

95 thoughts to “【BZOJ 3566】[SHOI2014] 概率充电器”

  1. Wonderful blog! I found it while surfing around on Yahoo News.
    Do you have any suggestions on how to get listed in Yahoo News?
    I’ve been trying for a while but I never seem to get there!

    Cheers

  2. I absolutely love your website.. Excellent colors & theme.

    Did you make this amazing site yourself? Please reply
    back as I’m trying to create my own personal blog
    and want to learn where you got this from or what the theme is called.
    Thank you!

  3. Hello there! This is my first comment here so I just wanted to give
    a quick shout out and say I genuinely enjoy reading through your
    posts. Can you recommend any other blogs/websites/forums that
    deal with the same topics? Thanks for your time!

  4. Right here is the perfect blog for everyone who really wants
    to find out about this topic. You know so much its almost hard to
    argue with you (not that I personally would
    want to…HaHa). You certainly put a new spin on a subject which has been written about for a long time.

    Excellent stuff, just excellent!

  5. naturally like your web site but you need to check the spelling on quite a
    few of your posts. Several of them are rife with spelling issues and I to find it very
    troublesome to tell the truth nevertheless I’ll definitely come back again.

  6. It’s a shame you don’t have a donate button!
    I’d most certainly donate to this outstanding blog! I suppose for now i’ll settle for bookmarking and adding your RSS feed to
    my Google account. I look forward to brand new updates and will talk about this website with my Facebook group.
    Chat soon!

  7. Hi, I think your website might be having browser
    compatibility issues. When I look at your website 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!
    plenty of fish natalielise

  8. I’m excited to uncover this website. I wanted to thank you for your time just for this wonderful read!!
    I definitely really liked every little bit of it and i also have you saved as a favorite to
    see new information on your website.

  9. The other day, while I was at work, my sister
    stole my iphone and tested to see if it can survive a 40 foot
    drop, just so she can be a youtube sensation. My iPad is now
    destroyed and she has 83 views. I know this is completely off topic but I had to share it with someone!

  10. I do believe all the ideas you’ve presented to
    your post. They are very convincing and will certainly work.
    Still, the posts are too quick for newbies.
    Could you please lengthen them a bit from subsequent time?

    Thank you for the post.

  11. Please let me know if you’re looking for a article writer for
    your weblog. You have some really great posts and I feel I
    would be a good asset. If you ever want to take some of the load off, I’d absolutely love to write some
    material for your blog in exchange for a link back to
    mine. Please shoot me an e-mail if interested.
    Many thanks!

  12. I am extremely impressed along with your writing abilities as neatly as with the layout in your
    weblog. Is that this a paid theme or did you customize it your self?
    Either way keep up the nice quality writing, it’s rare to
    look a nice blog like this one nowadays..

  13. Hi! Do you know if they make any plugins to help with Search Engine Optimization?
    I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very
    good gains. If you know of any please share.
    Many thanks!

  14. Hello, Neat post. There is a problem with your website in web explorer, might test this?
    IE nonetheless is the market leader and a huge section of other folks will pass over your magnificent
    writing due to this problem.

  15. Your style is really unique in comparison to
    other people I’ve read stuff from. I appreciate you for posting when you have the opportunity,
    Guess I’ll just book mark this web site.

  16. Pretty nice post. I just stumbled upon your blog and
    wished to say that I’ve really enjoyed surfing around your blog posts.
    In any case I will be subscribing to your rss feed and I hope you
    write again soon!

  17. My brother recommended I might like this web site.
    He was totally right. This put up actually made my day.
    You cann’t consider simply how a lot time I had spent for this information! Thanks!

  18. Having read this I thought it was very informative.
    I appreciate you spending some time and energy to put this short article together.
    I once again find myself spending way too much time both reading and commenting.

    But so what, it was still worthwhile!

  19. Aw, this was an incredibly nice post. Taking a few minutes and actual effort to create a
    really good article… but what can I say… I
    hesitate a whole lot and don’t seem to get anything done.

  20. Undeniably believe that which you said. Your favorite justification seemed to be on the web the easiest thing to be aware of.
    I say to you, I certainly get annoyed while people think about worries that they just do not know about.

    You managed to hit the nail upon the top as well as defined
    out the whole thing without having side-effects ,
    people could take a signal. Will probably be back to get more.

    Thanks

  21. I’ve been browsing online more than 4 hours today, yet I never found any interesting article like yours.
    It is pretty worth enough for me. In my opinion, if
    all site owners and bloggers made good content as you did, the web will be much more useful
    than ever before.

  22. Its like you read my mind! You appear to know so much
    about this, like you wrote the book in it or something.
    I think that you could do with a few pics to drive
    the message home a bit, but instead of that, this is fantastic blog.
    A great read. I’ll definitely be back.

  23. I know this if off topic but I’m looking into starting my own weblog and was curious what all is required to get setup?
    I’m assuming having a blog like yours would cost a pretty penny?
    I’m not very internet savvy so I’m not 100% positive.
    Any suggestions or advice would be greatly appreciated.
    Thanks

  24. obviously like your web site but you need to check the
    spelling on quite a few of your posts. Several of them
    are rife with spelling problems and I in finding it very
    bothersome to inform the reality then again I will surely come back again.

  25. I know this if off topic but I’m looking
    into starting my own weblog and was wondering what
    all is required to get set up? I’m assuming having a blog like yours would cost a pretty penny?

    I’m not very web savvy so I’m not 100% sure.
    Any tips or advice would be greatly appreciated.
    Kudos

  26. What i do not realize is if truth be told how you’re now not really much
    more well-liked than you might be right now.
    You are so intelligent. You understand thus considerably
    in relation to this subject, made me in my view consider it from so many varied angles.
    Its like women and men aren’t interested except it’s
    one thing to do with Girl gaga! Your personal
    stuffs great. Always maintain it up!

  27. I am really impressed together with your writing abilities and also with the format in your blog.

    Is that this a paid subject matter or did you customize it your
    self? Anyway stay up the excellent quality writing, it’s uncommon to peer a nice weblog like
    this one today..

  28. I’ll right away grasp your rss as I can’t in finding your email subscription hyperlink
    or newsletter service. Do you’ve any? Please let me realize so
    that I could subscribe. Thanks.

  29. I am not sure where you are getting your info, but good topic.
    I needs to spend some time learning more or understanding more.
    Thanks for fantastic information I was looking for this information for my mission.

  30. A person necessarily help to make seriously articles I would state.
    That is the very first time I frequented your web page and thus far?

    I surprised with the research you made to make this actual post extraordinary.
    Excellent activity!

  31. Wonderful items from you, man. I’ve bear in mind
    your stuff prior to and you’re simply too wonderful. I really like what you’ve received right here, really like
    what you’re saying and the best way during which you assert it.
    You make it entertaining and you continue to take
    care of to keep it smart. I can’t wait to read far more from you.
    This is actually a great web site.

  32. Excellent post. I was checking continuously this blog and I am impressed!
    Very helpful information specifically the last part 🙂 I
    care for such information a lot. I was looking for this certain info for a very long
    time. Thank you and best of luck.

  33. Hmm it appears like your site ate my first comment (it was extremely long) so I guess I’ll
    just sum it up what I had written and say, I’m thoroughly enjoying
    your blog. I too am an aspiring blog writer but I’m still new to
    everything. Do you have any tips for rookie blog writers?
    I’d certainly appreciate it.

  34. I’m not sure where you are getting your info, but
    good topic. I needs to spend some time learning more or understanding more.
    Thanks for excellent information I was looking for this info for my mission.

  35. I’m very happy to uncover this page. I want to to thank you for your time due
    to this fantastic read!! I definitely loved every part of
    it and i also have you book marked to check out new things on your
    web site.

  36. Howdy would you mind letting me know which hosting company you’re working with?

    I’ve loaded your blog in 3 completely different browsers and I must say this blog loads a lot faster then most.

    Can you recommend a good internet hosting provider at a reasonable price?
    Thanks, I appreciate it!

  37. all the time i used to read smaller articles or reviews that also clear their motive, and
    that is also happening with this piece of writing which I
    am reading at this time.

  38. When I initially left a comment I appear to have clicked on the -Notify me when new
    comments are added- checkbox and now each time a comment is added I get four emails with the same
    comment. Perhaps there is an easy method you are able to remove me from that service?
    Cheers!

  39. I think this is among the most important information for me.

    And i am glad reading your article. But wanna remark on few general
    things, The website style is wonderful, the articles is
    really great : D. Good job, cheers

  40. Hello my family member! I wish to say that this post is amazing,
    nice written and include almost all significant infos. I would like to
    see more posts like this .

  41. If some one wishes expert view regarding blogging after that i
    propose him/her to pay a quick visit this website, Keep up the fastidious work.

  42. Does your blog have a contact page? I’m having problems locating
    it but, I’d like to send you an email. I’ve got some ideas for your
    blog you might be interested in hearing. Either way, great blog and I look forward to seeing it develop over
    time.

  43. Please let me know if you’re looking for a writer
    for your weblog. You have some really good articles and I feel I would be a good asset.

    If you ever want to take some of the load off, I’d absolutely love to write some content for your blog in exchange for a link back to mine.
    Please blast me an e-mail if interested. Regards!

  44. Do you mind if I quote a few of your posts as long as I
    provide credit and sources back to your webpage?
    My blog site is in the very same area of interest as yours
    and my visitors would certainly benefit from some of the
    information you present here. Please let me know if this okay with you.
    Regards!

Leave a Reply

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