hdu 5036 Explosion

来源:互联网 发布:php抓取商品信息 编辑:程序博客网 时间:2024/05/29 17:03

bitset真是黑科技

#pragma comment(linker, "/STACK:102400000,102400000")#include<iostream>#include<vector>#include<algorithm>#include<cstdio>#include<queue>#include<stack>#include<string>#include<map>#include<set>#include<cmath>#include<cassert>#include<cstring>#include<iomanip>#include<bitset>using namespace std;#ifdef _WIN32#define i64 __int64#define out64 "%I64d\len"#define in64 "%I64d"#else#define i64 long long#define out64 "%lld\len"#define in64 "%lld"#endif/************ for topcoder by zz1215 *******************/#define foreach(c,itr)  for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)#define FOR(i,a,b)      for( int i = (a) ; i <= (b) ; i ++)#define FF(i,a)         for( int i = 0 ; i < (a) ; i ++)#define FFD(i,a,b)      for( int i = (a) ; i >= (b) ; i --)#define S64(a)          scanf(in64,&a)#define SS(a)           scanf("%d",&a)#define LL(a)           ((a)<<1)#define RR(a)           (((a)<<1)+1)#define pb              push_back#define pf              push_front#define X               first#define Y               second#define CL(Q)           while(!Q.empty())Q.pop()#define MM(name,what)   memset(name,what,sizeof(name))#define MC(a,b)memcpy(a,b,sizeof(b))#define MAX(a,b)        ((a)>(b)?(a):(b))#define MIN(a,b)        ((a)<(b)?(a):(b))#define read            freopen("out.txt","r",stdin)#define write           freopen("out2.txt","w",stdout)const int maxn = 1111;int n;bitset<maxn>dp[maxn];void gao(){for (int k = 1; k <= n; k++){for (int now = 1; now <= n; now++){if (dp[now][k]){dp[now] |= dp[k];}}}}int main(){int T;cin >> T;for (int tt = 1; tt <= T; tt++){cin >> n;for (int i = 1; i <= n; i++){dp[i].reset();dp[i][i] = 1;}int x, to;for (int now = 1; now <= n; now++){//cin >> x;SS(x);for (int i = 1; i <= x; i++){//cin >> to;SS(to);dp[now][to] = 1;}}gao();double ans = 0.0;int cnt;for (int i = 1; i <= n; i++){cnt = 0;for (int j = 1; j <= n; j++){if (dp[j][i]){cnt++;}}ans += 1.0 / (double)(cnt);}printf("Case #%d: %.5lf\n", tt, ans);}return 0;}


0 0
原创粉丝点击