Big Buns Play games

Source: Internet
Author: User
Tags bitset

Portal-->qwq (seems to be: ACM/ICPC Asia Regional Beijing online-e)

Description

There are \ (n\) rooms, each room may have some other room keys, the initial time all the doors are locked, random bombing doors, asked how many times to explode to open all the rooms

Data range:\ (n<=1000\)
  

Solution

Daily expectations are not counted.

The idea of comparison is of course to build a map, each room with the room key corresponding to the room with a straight edge, then the problem becomes. Delete the point in a graph above (delete all points that can be reached at a point) and ask how many times you wish to delete the whole picture.

Overall bad consideration, we directly consider its contribution to every point

Here a little. Describe the specific meaning of the "contribution" that follows: without considering the expectation, a point-to-answer has a 1\ contribution, and if and only when the point is deleted, the selected point is itself

For a point, we remember that the point set that can reach this point is \ (s\), then the operation of deleting this point has a total of \ (| s|\) species, but only one of them is chosen, so a point's expectation of contributing to the answer is \ (\frac{1}{| s|} \)

And then we'll find the answer to all the points we want to contribute.

? Now the question is how to calculate \ (s\), that ... Anyway \ (n=1000\)... That.. Let's shrink the point and turn it into a DAG and then bitset remember what points we can get to each SCC, and then go straight to the topology sort and move on.

  

? The code probably looks like this.

#include <iostream> #include <cstdio> #include <cstring> #include <queue> #include <bitset >using namespace Std;const int n=1010;struct xxx{int y,nxt;} a[n*n*2];queue<int> q;int h[n],in[n],dfn[n],low[n],inst[n],st[n],h1[n];int bl[N],sz[N];bitset<N> Ok[N] ;d ouble ans;int n,m,t,tot,dfn_t,top,cnt;void Add (int x,int y,int *h) {a[++tot].y=y; a[tot].nxt=h[x]; h[x]=tot;}    void Tarjan (int x) {int u; dfn[x]=low[x]=++dfn_t; Inst[x]=1;    St[++top]=x;        for (int i=h[x];i!=-1;i=a[i].nxt) {u=a[i].y;            if (!dfn[u]) {Tarjan (U);        Low[x]=min (Low[x],low[u]);    } else if (Inst[u]) low[x]=min (Low[x],dfn[u]);        } if (Low[x]==dfn[x]) {++cnt; sz[cnt]=0; Ok[cnt].reset ();            while (st[top]!=x) {bl[st[top]]=cnt;            Ok[cnt][st[top]]=1;            inst[st[top--]]=0;        ++SZ[CNT]; } bl[x]=cnt; --top;        ++SZ[CNT]; inst[x]=0;    Ok[cnt][x]=1; }}void rebuild () {CNT= 0; dfn_t=0;    Top=0;    for (int i=1;i<=n;++i) if (!dfn[i]) Tarjan (i);    memset (H1,-1,sizeof (H1));            for (int i=1;i<=n;++i) {for (int j=h[i];j!=-1;j=a[j].nxt) {if (bl[i]==bl[a[j].y]) continue;            Add (BL[I],BL[A[J].Y],H1);        ++IN[BL[A[J].Y]];    }}}void Calc () {int u,v;    Rebuild ();    while (!q.empty ()) Q.pop ();    for (int i=1;i<=n;++i) if (in[i]==0) Q.push (i);        while (!q.empty ()) {V=q.front (); Q.pop ();            for (int i=h1[v];i!=-1;i=a[i].nxt) {u=a[i].y;            OK[U]|=OK[V];            --in[u];        if (!in[u]) Q.push (U);    }}}void Get_ans () {int tmp;    ans=0;        for (int i=1;i<=cnt;++i) {tmp=ok[i].count ();        if (!tmp) continue;    ans+= (1.0*sz[i])/(1.0*TMP);    }}void Init () {for (int i=1;i<=n;++i) h[i]=-1,in[i]=0,dfn[i]=0; tot=0;}    int main () {#ifndef Online_judge freopen ("a.in", "R", stdin), #endif int x,num;  scanf ("%d", &t);  for (int o=1;o<=t;++o) {scanf ("%d", &n);        Init ();            for (int i=1;i<=n;++i) {scanf ("%d", &num);                for (int j=1;j<=num;++j) {scanf ("%d", &x);            Add (i,x,h);        }} calc ();        Get_ans (); for (int i=1;i<=n;++i) printf ("%d", Ok[i].count ());        printf ("\ n");    printf ("Case #%d:%.5lf\n", O,ans); }}

Big buns play games

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.