记录编号 |
446458 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[HAOI 2015]按位或 |
最终得分 |
100 |
用户昵称 |
__stdcall |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
1.680 s |
提交时间 |
2017-09-08 11:45:12 |
内存使用 |
8.29 MiB |
显示代码纯文本
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
const int MAXN = 20;
const double EPS = 1e-10;
int nowarn;
int dcmp( double x ) {
if( fabs(x) < EPS ) return 0;
return x < 0 ? -1 : 1;
}
int n;
double a[1<<MAXN];
bool check() {
bool vis[MAXN] = {0};
for( int i = 0; i < (1<<n); ++i )
if( dcmp( a[i] ) )
for( int j = 0; j < n; ++j )
if( i & (1<<j) ) vis[j] = 1;
for( int i = 0; i < n; ++i )
if( !vis[i] ) return false;
return true;
}
void fmt( double *a, int n ) {
for( int i = 0; i < n; ++i )
for( int j = 0; j < (1<<n); ++j )
if( j & (1<<i) )
a[j] += a[j ^ (1<<i)];
}
void ifmt( double *a, int n ) {
for( int i = n-1; i >= 0; --i )
for( int j = (1<<n)-1; j >= 0; --j )
if( j & (1<<i) )
a[j] -= a[j ^ (1<<i)];
}
int main() {
freopen( "haoi2015_set.in", "r", stdin );
freopen( "haoi2015_set.out", "w", stdout );
nowarn = scanf( "%d", &n );
for( int i = 0; i < (1<<n); ++i )
nowarn = scanf( "%lf", a+i );
if( !check() ) {
puts("INF");
return 0;
}
fmt(a, n);
for( int i = 0; i < (1<<n); ++i ) {
if( dcmp( a[i] - 1 ) == 0 )
a[i] = 0;
else
a[i] = 1 / ( a[i] - 1 );
}
ifmt(a, n);
printf( "%.10lf\n", a[(1<<n)-1] );
return 0;
}