记录编号 |
160579 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[HAOI 2015]按位或 |
最终得分 |
100 |
用户昵称 |
Asm.Def |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
1.778 s |
提交时间 |
2015-04-28 20:24:38 |
内存使用 |
8.29 MiB |
显示代码纯文本
/***********************************************************************/
/**********************By Asm.Def-Wu Jiaxin*****************************/
/***********************************************************************/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <algorithm>
using namespace std;
#define SetFile(x) ( freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout) );
//#define UseFREAD
#ifdef UseFREAD
#define getc() *(file_ptr++)
#define FreadLenth 5000000
char CHARPOOL[FreadLenth], *file_ptr = CHARPOOL;
#else
#define getc() getchar()
#endif
#ifdef DEBUG
#include <sys/timeb.h>
timeb SysTp;
#endif
template<class T>inline void getd(T &x){
char ch = getc();bool neg = false;
while(!isdigit(ch) && ch != '-')ch = getc();
if(ch == '-')ch = getc(), neg = true;
x = ch - '0';
while(isdigit(ch = getc()))x = x * 10 - '0' + ch;
if(neg)x = -x;
}
/***********************************************************************/
const int maxn = 1 << 20;
const double eps = 1e-8;
double P[maxn];
int n, N;
inline double m_abs(double x) {return x < 0 ? -x : x;}
inline void work(){
getd(n);N = 1 << n;
int i, j, t, tmp;
for(i = 0;i < N;++i){
scanf("%lf", P + i);
if(P[i])tmp |= i;
}
if(tmp+1 != N){
puts("INF");
return;
}
for(t = 1;t < N;t <<= 1)//Modulate
for(j = 0;j < N;++j)if(j & t)P[j] += P[j ^ t];
for(j = 0;j < N;++j){
if(m_abs(P[j] - 1.0) < eps)P[j] = 0;
else P[j] = 1.0 / (P[j] - 1.0);
}
for(t = 1;t < N;t <<= 1)//Demodulate
for(j = 0;j < N;++j)if(j & t)P[j] -= P[j ^ t];
printf("%.10lf\n", P[N - 1]);
}
int main(){
#ifdef DEBUG
freopen("test.txt", "r", stdin);ftime(&SysTp);
size_t Begin_sec = SysTp.time, Begin_mill = SysTp.millitm;
#elif !defined ONLINE_JUDGE
SetFile(haoi2015_set);
#endif
#ifdef UseFREAD
fread(file_ptr, 1, FreadLenth, stdin);
#endif
work();
#ifdef DEBUG
ftime(&SysTp);
printf("\n%.3lf sec \n", (SysTp.time - Begin_sec) + (SysTp.millitm - Begin_mill) / 1000.0);
#endif
return 0;
}