RT,赛时坐牢2h,请问是假了还是写挂了。
加了一点注释
#include<bits/stdc++.h>
using namespace std;
inline char gc()
{
static char BB[1000000], * S = BB, * T = BB;
return (S == T) && (T = (S = BB) + fread(BB, 1, 1000000, stdin), S == T) ? EOF : *S++;
}
template <typename T>
T read(){
T x = 0, f = 1;
char ch = gc();
while(ch < '0' || ch > '9'){if (ch == '-') f = -1; ch = gc();}
while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0'; ch = gc();}
return x * f;
}
template <> double read<double> (){
double x = 0;
int f = 1;
char ch = gc();
while(ch < '0' || ch > '9'){if (ch == '-') f = -1; ch = gc();}
while(ch >= '0' && ch <= '9'){x = x * double(10) + double(ch - '0'); ch = gc();}
if(ch == '.'){
ch = gc();
double now = 1;
while(ch >= '0' && ch <= '9'){
now /= double(10);
x = x + now * double(ch - '0');
ch = gc();
}
}
return x * f;
}
template <typename T>
void read(T & t){
T x = 0, f = 1;
char ch = gc();
while(ch < '0' || ch > '9'){if (ch == '-') f = -1; ch = gc();}
while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0'; ch = gc();}
t = x * f;
}
template <> void read<double> (double & t){
double x = 0;
int f = 1;
char ch = gc();
while(ch < '0' || ch > '9'){if (ch == '-') f = -1; ch = gc();}
while(ch >= '0' && ch <= '9'){x = x * double(10) + double(ch - '0'); ch = gc();}
if(ch == '.'){
ch = gc();
double now = 1;
while(ch >= '0' && ch <= '9'){
now /= double(10);
x = x + now * double(ch - '0');
ch = gc();
}
}
t = x * f;
}
template <typename T, typename...Args>
void read(T & value, Args & ... args){
read(value);
read(args...);
}
template <typename T>
void sprint(T x, int w = 0){
if(x < 0){putchar('-'); x = -x;}
char ch[20];
int t = 0;
while(x){
ch[++t] = x % 10 + '0';
x /= 10;
}
for(int i = t; i >= 1; i--){
putchar(ch[i]);
}
if(t == 0) putchar('0');
switch(w){
case 1:{
putchar(' ');
break;
}
case 2:{
putchar('\n');
break;
}
default:{
break;
}
}
}
template<typename T>
void mprint(const T & value){
T x = value;
sprint(x, 2);
}
template<typename T, typename ...Args>
void mprint(const T & value, const Args & ... args){
T x = value;
sprint(x, 1);
mprint(args...);
}
const int N = 1005;
const double eps = 1e-6;
int n, x[N];
struct spec{
int tot;
pair<double, double> data[N];
spec(){
tot = 0;
}
spec & operator=(const spec & B){
tot = B.tot;
for(int i = 1; i <= tot; i++) data[i] = B.data[i];
return *this;
}
}pre, now;//存每个x_i的答案的区间
//计算x_i的答案的区间
void make_spec(spec & sp, int i){
sp.tot = 0;
for(int k = i; k >= 1; k--){
sp.data[++sp.tot].first = double(i) / double(k);
sp.data[sp.tot].second = double(i + 1) / double(k);
}
}
void print(spec & sp){
for(int i = 1; i <= sp.tot; i++){
printf("<%.7lf %.7lf> ", sp.data[i].first, sp.data[i].second);
}
putchar('\n');
}
//合并区间
spec Union(const spec & A, const spec & B){
spec ret;
for(int i = 1, j = 1; i <= A.tot; i++){
while(j <= B.tot && A.data[i].first > B.data[j].second) ++j;
while(j <= B.tot && A.data[i].second > B.data[j].first){
++ret.tot;
ret.data[ret.tot] = make_pair(max(A.data[i].first, B.data[j].first), min(A.data[i].second, B.data[j].second));
if(ret.data[ret.tot].second < ret.data[ret.tot].first + eps) --ret.tot;
//printf("%d %.7lf %.7lf %.7lf %.7lf\n", ret.tot, A.data[i].first, B.data[j].first, A.data[i].second, B.data[j].second);
++j;
}
if(j > B.tot) break;
}
return ret;
}
int main(){
read(n);
for(int i = 1; i <= n; i++){
read(x[i]);
}
make_spec(pre, x[1]);
//print(pre);
for(int i = 2; i <= n; i++){
make_spec(now, x[i]);
//print(now);
pre = Union(pre, now);//把每个now合并到pre上
//print(pre);
}
//print(pre);
for(int i = pre.tot; i >= 1; i--){
if(pre.data[i].second - pre.data[i].first > eps){
printf("%.7lf\n", pre.data[i].second);
break;
}
}
return 0;
}