关闭

2016_NENU_SoftWare_Summer_ Training_4

269人阅读 评论(0) 收藏 举报
分类:

Problem A UVALive 7000 Present Problem

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define xx first
#define yy second
#define LL long long
#define MP make_pair
#define INF 0x3f3f3f3f
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1|1
#define CLR(a, b) memset(a, b, sizeof(a))
using namespace std;
const int maxn = 101000;

pair<int, int> p[maxn];
int ans[maxn], pt[maxn];

int n, m, l;

void solve()
{
    sort(p, p + m);
    m = unique(p, p + m) - p;
    for(int i = 0; i < n; i ++)
        ans[i] = i;
    for(int i = 0; i < m; i ++)
    {
        int u = p[i].yy, v = u + 1;
        if(v >= n) continue;
        swap(ans[u], ans[v]);
    }
    for(int i = 0; i < n; i ++)
        pt[ans[i]] = i;
    for(int i = 0; i < n; i ++)
        printf("%d\n", pt[i]);
}

int main()
{
    int T; scanf("%d", &T);
    while(T --)
    {
        scanf("%d%d%d", &n, &m, &l);
        for(int i = 0; i < m; i ++)
        {
            scanf("%d%d", &p[i].yy, &p[i].xx);
        }
        solve();
    }
    return 0;
}


Problem B UVALive 7001 Bus Problem

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<ctime>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define xx first
#define yy second
#define LL long long
#define MP make_pair
#define INF 0x3f3f3f3f
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1|1
#define CLR(a, b) memset(a, b, sizeof(a))
using namespace std;

const int maxn = 1500;

vector<pair<int, int> > v[maxn];
int dis[maxn];
bool vis[maxn];

int solve(int x,int n) {
    memset(vis, 0, sizeof vis);
    memset(dis, INF, sizeof dis);
    vis[x] = true;
    dis[x] = 0;
    queue<int> q;
    q.push(x);
    int ret = 0;
    while(!q.empty()) {
        int x = q.front();
        q.pop();
        for(int i = 0; i < v[x].size(); i ++) {
            int y = v[x][i].first;
            int w = v[x][i].second;
            if(vis[y]) continue;
            dis[y] = min(dis[y], w);
        }
        int next = -1;
        int nowVal = INF;
        for(int i = 0; i < n; i ++) {
            if(vis[i]) continue;
            if(nowVal > dis[i]) {
                next = i;
                nowVal = dis[i];
            }
        }
        if(next == -1) break;
        ret += nowVal;
        vis[next] = true;
        q.push(next);
    }
    return  ret;
}

int main() {
    int t, c, r;
    cin >> t;
    while(t --) {
        cin >> c >> r;
        for(int i = 0; i < c; i ++) {
            v[i].clear();
        }
        int all = 0;
        while(r --) {
            int a, b, w;
            scanf("%d%d%d", &a, &b, &w);
            all += w;
            v[a].push_back(make_pair(b, w));
            v[b].push_back(make_pair(a, w));
        }
        printf("%d\n", all - solve(0, c));
    }
    return 0;
}


Problem C UVALive 7002 Queen on Horse

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define xx first
#define yy second
#define LL long long
#define MP make_pair
#define INF 0x3f3f3f3f
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1|1
#define CLR(a, b) memset(a, b, sizeof(a))
using namespace std;

const int maxn = 20;
int vis[maxn][maxn];
int t, n, m;

bool inMap(int x, int y) {
    if(x < 0 || x >= n || y < 0 || y >= n) return false;
    return true;
}

int lftEmp;

void fillIn(int a, int b){
    int x, y;
    x = a, y = b; while(inMap(x, y)) { if(!vis[x][y]) lftEmp --; vis[x][y] ++; x ++; }
    x = a, y = b; while(inMap(x, y)) { if(!vis[x][y]) lftEmp --; vis[x][y] ++; x --; }
    x = a, y = b; while(inMap(x, y)) { if(!vis[x][y]) lftEmp --; vis[x][y] ++; y ++; }
    x = a, y = b; while(inMap(x, y)) { if(!vis[x][y]) lftEmp --; vis[x][y] ++; y --; }
    x = a, y = b; while(inMap(x, y)) { if(!vis[x][y]) lftEmp --; vis[x][y] ++; x ++, y ++; }
    x = a, y = b; while(inMap(x, y)) { if(!vis[x][y]) lftEmp --; vis[x][y] ++; x --, y ++; }
    x = a, y = b; while(inMap(x, y)) { if(!vis[x][y]) lftEmp --; vis[x][y] ++; x ++, y --; }
    x = a, y = b; while(inMap(x, y)) { if(!vis[x][y]) lftEmp --; vis[x][y] ++; x --, y --; }

    x = a, y = b; while(inMap(x, y)) { if(!vis[x][y]) lftEmp --; vis[x][y] ++; x += 2, y ++; }
    x = a, y = b; while(inMap(x, y)) { if(!vis[x][y]) lftEmp --; vis[x][y] ++; x += 2, y --; }
    x = a, y = b; while(inMap(x, y)) { if(!vis[x][y]) lftEmp --; vis[x][y] ++; x ++, y -= 2; }
    x = a, y = b; while(inMap(x, y)) { if(!vis[x][y]) lftEmp --; vis[x][y] ++; x ++, y += 2; }
    x = a, y = b; while(inMap(x, y)) { if(!vis[x][y]) lftEmp --; vis[x][y] ++; x --, y -= 2; }
    x = a, y = b; while(inMap(x, y)) { if(!vis[x][y]) lftEmp --; vis[x][y] ++; x --, y += 2; }
    x = a, y = b; while(inMap(x, y)) { if(!vis[x][y]) lftEmp --; vis[x][y] ++; x -= 2, y ++; }
    x = a, y = b; while(inMap(x, y)) { if(!vis[x][y]) lftEmp --; vis[x][y] ++; x -= 2, y --; }
    vis[a][b] = 1;
}

void putUp(int a, int b){
    int x, y;
    x = a, y = b; while(inMap(x, y)) { vis[x][y] --; if(!vis[x][y]) lftEmp ++; x ++; }
    x = a, y = b; while(inMap(x, y)) { vis[x][y] --; if(!vis[x][y]) lftEmp ++; x --; }
    x = a, y = b; while(inMap(x, y)) { vis[x][y] --; if(!vis[x][y]) lftEmp ++; y ++; }
    x = a, y = b; while(inMap(x, y)) { vis[x][y] --; if(!vis[x][y]) lftEmp ++; y --; }
    x = a, y = b; while(inMap(x, y)) { vis[x][y] --; if(!vis[x][y]) lftEmp ++; x ++, y ++; }
    x = a, y = b; while(inMap(x, y)) { vis[x][y] --; if(!vis[x][y]) lftEmp ++; x --, y ++; }
    x = a, y = b; while(inMap(x, y)) { vis[x][y] --; if(!vis[x][y]) lftEmp ++; x ++, y --; }
    x = a, y = b; while(inMap(x, y)) { vis[x][y] --; if(!vis[x][y]) lftEmp ++; x --, y --; }

    x = a, y = b; while(inMap(x, y)) { vis[x][y] --; if(!vis[x][y]) lftEmp ++; x += 2, y ++; }
    x = a, y = b; while(inMap(x, y)) { vis[x][y] --; if(!vis[x][y]) lftEmp ++; x += 2, y --; }
    x = a, y = b; while(inMap(x, y)) { vis[x][y] --; if(!vis[x][y]) lftEmp ++; x ++, y -= 2; }
    x = a, y = b; while(inMap(x, y)) { vis[x][y] --; if(!vis[x][y]) lftEmp ++; x ++, y += 2; }
    x = a, y = b; while(inMap(x, y)) { vis[x][y] --; if(!vis[x][y]) lftEmp ++; x --, y -= 2; }
    x = a, y = b; while(inMap(x, y)) { vis[x][y] --; if(!vis[x][y]) lftEmp ++; x --, y += 2; }
    x = a, y = b; while(inMap(x, y)) { vis[x][y] --; if(!vis[x][y]) lftEmp ++; x -= 2, y ++; }
    x = a, y = b; while(inMap(x, y)) { vis[x][y] --; if(!vis[x][y]) lftEmp ++; x -= 2, y --; }
    vis[a][b] = 0;
}

int xx[500], yy[500];
int out[500];
int ans, cnt;

bool judge(int x, int y, int now) {
    for(int i = 0; i < now; i ++) {
        int dtx = abs(xx[i] - x);
        int dty = abs(yy[i] - y);
        if(dtx == dty || dty == 2 * dtx || dty * 2 == dtx || dtx * dty == 0) return false;
    }
    return true;
}

void dfs(int x, int y, int now) {
    if(y == n) {
        x ++;
        y = 0;
    }

//    printf("%d %d %d\n", x, y, now);
    if(x == n) {
        out[now] ++;
        ans = max(ans, now);
        return ;
    }

    dfs(x, y + 1, now);
    if(judge(x, y, now)){
        xx[now] = x;
        yy[now] = y;
        dfs(x, y + 1, now + 1);
    }
}

int main() {
    cin >> t;
    while(t --) {
        cin >> n >> m;
        memset(vis, 0, sizeof vis);
        memset(out, 0, sizeof out);
        for(int i = 0; i < m; i ++) {
            int a, b;
            scanf("%d%d", &a, &b);
            xx[i] = a;
            yy[i] = b;
        }
        ans = 0;
        dfs(0, 0, m);
        printf("%d %d\n", ans, out[ans]);
    }
    return 0;
}


Problem D UVALive 7003 A Balance Game on Trees

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define xx first
#define yy second
#define LL long long
#define MP make_pair
#define INF 0x3f3f3f3f
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1|1
#define CLR(a, b) memset(a, b, sizeof(a))
using namespace std;

const int maxn = 111;

vector<int> G[maxn];

int n, k;

char ch[101000];

int dp[maxn][3]; /// 0 -> b  1 -> k-1 w   2 -> k w

void dfs(int u, int fa)
{
    vector<int> vec;
    int now = 1;
    CLR(dp[u], -1);
    int sum1 = 0, sum2 = 0;
    int cnt = 0;
    for(int i = 0; i < G[u].size(); i ++)
    {
        int v = G[u][i];
        if(v == fa) continue;
        dfs(v, u);
        sum1 += max(dp[v][0], dp[v][1]);
        if(dp[v][2] != -1) sum2 += dp[v][2], vec.push_back(dp[v][0] - dp[v][2]);
        else
        {
            cnt ++; sum2 += dp[v][0];
        }
    }
    dp[u][0] = sum1;
    if(cnt > k) return;
    if(cnt == k)
    {
        dp[u][2] = sum2 + 1;
        return ;
    }
    sort(vec.begin(), vec.end());
    int tmp = 0;
    if(k - 1 - cnt == 0) dp[u][1] = sum2 + 1;
    for(int i = 1; i <= k && i <= vec.size(); i ++)
    {
        tmp += vec[i - 1];
        if(k - 1 - cnt == i)dp[u][1] = sum2 + tmp + 1;
        if(k - cnt == i) dp[u][2] = sum2 + tmp + 1;
    }
//    printf("%d -- %d %d %d\n", u, dp[u][0], dp[u][1], dp[u][2]);
}

void solve()
{
    if(k == 0)
    {
        printf("%d\n", n);
        return ;
    }
    dfs(1, -1);
    int ans = max(dp[1][0], dp[1][2]);
    printf("%d\n", ans);
}

int main()
{
    int T; scanf("%d", &T);
    while(T --)
    {
        scanf("%d%d", &n, &k);
        for(int i = 1; i <= n; i ++)
            G[i].clear();
        getchar();
        for(int i = 1; i <= n; i ++)
        {
            gets(ch);
            int len = strlen(ch);
            for(int j = 0; j < len; j ++)
            {
                while(j < len && ch[j] < '0' && ch[j] > '9') j ++;
                if(j == len) break;
                int v = 0;
                while(j < len && ch[j] >= '0' && ch[j] <= '9') v = v * 10 + ch[j ++] - '0';
                if(v == 0) break;
                G[i].push_back(v);
//                printf("%d - %d\n", i, v);
            }
        }
        solve();
    }
    return 0;
}


Problem E UVALive 7004 Inside, Outside or On

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define xx first
#define yy second
#define LL long long
#define MP make_pair
#define INF 0x3f3f3f3f
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1|1
#define CLR(a, b) memset(a, b, sizeof(a))
using namespace std;
const double eps=1e-8;

int sign(double x){
    return (x>eps)-(x<-eps);
}

struct Point{
    double x,y;
    Point(){}
    Point(double x,double y):x(x),y(y){}
    Point operator-(const Point &a){
        return Point(x-a.x,y-a.y);
    }
    double operator*(const Point &a){
        return x*a.y-y*a.x;
    }
    double operator^(const Point &a){
        return x*a.x+y*a.y;
    }
    void input(){
        scanf("%lf%lf",&x,&y);
    }
}p[16],P;

bool pnt_on_seg(Point p,Point u,Point v){
    return ((p-u)^(p-v))<eps;
}

int ans[16];

int inside(Point p[],int n,Point t){
    int cnt=0;
    for(int i=0;i<n;i++){
        Point p1=p[i];
        Point p2=p[(i+1)%n];
        if(sign((p2-p1)*(t-p1))==0&&pnt_on_seg(t,p1,p2)) return 2;
        if(p1.y==p2.y) continue;
        if(t.y<min(p1.y,p2.y)) continue;
        if(t.y>=max(p1.y,p2.y)) continue;
        double x=(t.y-p1.y)*(p2.x-p1.x)/(p2.y-p1.y)+p1.x;
        if(x>t.x) cnt++;
    }
    return cnt%2==1;
}

int main(){
    int T;scanf("%d",&T);
    while(T--){
        int n;scanf("%d",&n);
        P.input();
        for(int i=1;i<=n;i++){
            int t;scanf("%d",&t);
            for(int j=0;j<t;j++) p[j].input();
            int tmp=inside(p,t,P);
            if(tmp==2) tmp=0;
            else if(tmp==0) tmp=2;
            ans[i]=tmp;
        }
        for(int i=1;i<=n;i++) printf("%d%c",ans[i],i==n?'\n':' ');
    }
}


Problem F UVALive 7005 Constrained maximum average

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define LL long long
#define MP make_pair
#define xx first
#define yy second
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1|1
#define CLR(a, b) memset(a, b, sizeof(a))
using namespace std;

int a[666][10100];
LL sum[10100];

bool useless(int Xa, int Xb, int Xc)
{
    return (sum[Xc] - sum[Xb]) * (Xb - Xa) <= (sum[Xb] - sum[Xa]) * (Xc - Xb);
}

int q[10100];
int m, n, k;

void solve()
{
    double ans = 0;
    for(int i = 1; i <= n; i ++)
    {
        CLR(sum, 0);
        for(int j = i; j <= n; j ++)
        {
            LL tmp = 0;
            for(int s = 1; s <= m; s ++)
            {
                tmp += a[j][s]; sum[s] += tmp;
            }
            int head = 0 , rear = -1;
            int tk =(k + (j - i)) / (j - i + 1);
            for(int s = tk; s <= m; s ++)
            {
                while(head < rear && useless(q[rear - 1], q[rear] ,s - tk))
                    -- rear;
                q[++rear] = s - tk;

                while(head < rear && useless(q[head + 1], q[head], s))
                    ++ head;
                ans = max(ans, (sum[s] - sum[q[head]]) * 1.0 / (s - q[head]) / (j - i + 1));
//                printf("%d %d -- %d %d  %f\n", i, j, q[head], s, sum[s] - sum[q[head]]);
            }
        }
    }
    printf("%.3f\n", ans);
}

int main()
{
    int T;
    scanf("%d", &T);
    while(T --)
    {
        scanf("%d%d%d", &n, &m, &k);
        for(int i = 1; i <= n; i ++)
        {
            for(int j = 1; j <= m; j ++)
                scanf("%d", &a[i][j]);
        }
        solve();
    }
    return 0;
}


Problem G UVALive 7006 Folding a Binary String

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define xx first
#define yy second
#define LL long long
#define MP make_pair
#define INF 0x3f3f3f3f
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1|1
#define CLR(a, b) memset(a, b, sizeof(a))
using namespace std;

int n;
char s[100];
int a[100], b[100];
int ans;
int vis[100000];
vector<int> v;
int nextx[] = {0, 0, -1, -1, -1, 1, 1, 1};
int nexty[] = {1, -1, 0, 1, -1, 0, -1, 1};

//map<pair<pair<int, int>, pair<int, int> >, int>le;
int le[50][50][50][50];
int topl;

int solve(){
//    le.clear();
    int rd = topl ++;
    int tmp = 0;
    for(int i = 1; i < n; i ++) {
//        pair<pair<int, int>, pair<int, int> > now = make_pair(make_pair(a[i], b[i]), make_pair(a[i - 1], b[i - 1]));
//        pair<pair<int, int>, pair<int, int> > opnow = make_pair(make_pair(a[i - 1], b[i - 1]), make_pair(a[i], b[i]));
//        pair<pair<int, int>, pair<int, int> > cros = make_pair(make_pair(a[i], b[i - 1]), make_pair(a[i - 1], b[i]));
        if(le[a[i] + 20][b[i - 1] + 20][a[i - 1] + 20][b[i] + 20] == rd) return 0;
        //if(le.find(cros) != le.end()) return 0;
        if(s[i] == '1' && s[i - 1] == '1') tmp ++;
        le[a[i - 1] + 20][b[i - 1] + 20][a[i] + 20][b[i] + 20] = rd;
        le[a[i] + 20][b[i] + 20][a[i - 1] + 20][b[i - 1] + 20] = rd;
//        le[now] = 1;
//        le[opnow] = 1;
    }
    int ret = 0;
    for(int i = 0; i < v.size(); i ++) {
        for(int j = i + 1; j < v.size() ; j ++) {
            if((a[v[i]] - a[v[j]]) * (a[v[i]] - a[v[j]]) + (b[v[i]] - b[v[j]]) * (b[v[i]] - b[v[j]]) <= 2) {
                ret ++;
            }
        }
    }
    return ret - tmp;
}

void dfs(int id){
//    puts("---");
    if(id == n) {
        ans = max(ans, solve());
        return ;
    }
    for(int i = 0; i < 8; i ++) {
        a[id] = a[id - 1] + nextx[i];
        b[id] = b[id - 1] + nexty[i];
        int opv = (a[id] + 20) * 100 + b[id] + 20;
        if(vis[opv]) continue;
        vis[opv] = true;
        dfs(id + 1);
        vis[opv] = false;
    }
}

int main() {
    int t;
    cin >> t;
    while(t --) {
        cin >> n;
        v.clear();
        memset(vis, 0, sizeof vis);
        scanf("%s", s);
        for(int i = 0; i < n; i ++) {
            if(s[i] == '0') continue;
            v.push_back(i);
        }
        ans = 0;
        a[0] = b[0] = 0;
        dfs(1);
        printf("%d\n", ans);
    }
    return 0;
}


Problem I UVALive 7008 Tactical Multiple Defense System

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define xx first
#define yy second
#define LL long long
#define MP make_pair
#define INF 0x3f3f3f3f
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1|1
#define CLR(a, b) memset(a, b, sizeof(a))
using namespace std;

const int MAXN = 5555;
const int MAXM = 55555;

struct Edge
{
    int to,next;
}edge[MAXM];
int head[MAXN],tot;
void init()
{
    tot = 0;
    CLR(head, -1);
}
void addEdge(int u,int v)
{
//    printf("%d -> %d\n", u, v);
    edge[tot].to = v;
    edge[tot].next = head[u];
    head[u] = tot++;
}
int linker[MAXN];
int used[MAXN];
int uN, when;

bool dfs(int u)
{
    for(int i = head[u];i != -1;i = edge[i].next)
    {
        int v = edge[i].to;
        if(used[v] != when)
        {
            used[v] = when;
            if(linker[v] == -1 || dfs(linker[v]))
            {
                linker[v] = u;
                return true;
            }
        }
    }
    return false;
}
int hungary()
{
    memset(linker,-1,sizeof(linker));
    CLR(used, 0);
    when = 0;
    int ret = 0;
    for(int u = 0; u < uN;u++)
    {
        when++;
        if(dfs(u)) ret ++;
    }
    return ret;
}

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}

map<pair<int, int>, int> mp;

int n;

struct Node
{
    int r, s, t;
    void in()
    {
        scanf("%d%d%d", &r, &s, &t);
        int g = gcd(s, t);
        s /= g; t /= g;
    }
    bool operator < (const Node& rhs) const
    {
        if(r == rhs.r)
        {
            if(s == rhs.s) return t < rhs.t;
            return s < rhs.s;
        }
        return r < rhs.r;
    }
    bool operator == (const Node& rhs) const
    {
        return r == rhs.r && s == rhs.s && t == rhs.t;
    }
}p[MAXN];

void solve()
{
    sort(p, p + n);
    n = unique(p, p + n) - p;
    uN = 5000;
    init(); mp.clear();
    int m = 0;
    for(int i = 0; i < n; i ++)
    {
        if(!mp.count(MP(p[i].s, p[i].t))) mp[MP(p[i].s, p[i].t)] = m ++;
        addEdge(p[i].r - 1000, mp[MP(p[i].s, p[i].t)]);
    }
    printf("%d\n", hungary());
}

int main()
{
    int T; scanf("%d", &T);
    while(T --)
    {
        scanf("%d", &n);
        for(int i = 0; i < n; i ++)
            p[i].in();
        solve();
    }
    return 0;
}


Problem J UVALive 7009 Secret Binary Tree

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define LL long long
#define MP make_pair
#define xx first
#define yy second
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1|1
#define CLR(a, b) memset(a, b, sizeof(a))
using namespace std;

const int maxn = 1 << 18;

double s[maxn], x[20];
int n;

void solve()
{
    int tot = 0;
    for(int i = 0; i < (1 << n); i ++)
    {
        int cnt = 0;
        for(int j = 0; j < n; j ++)
            if((i >> j) & 1) cnt ++;
        if(cnt < 2) continue;
        double l = 0, r = 1e4;
        while(l <= r - 1e-8)
        {
            double mid = (l + r) * 0.5;
            double tmp = 0;
            for(int j = 0; j < n; j ++)
            {
                if((i >> j) & 1)
                {
                    tmp += pow(x[j], mid);
                }
                if(tmp > 1.0) break;
            }
//            printf("%f --\n", tmp);
            if(tmp >= 1.0) l = mid;
            else r = mid;
        }
        s[tot ++] = l;
    }
    if(tot == 1)
    {
        printf("%.6f\n", s[0]);
        return ;
    }
    sort(s, s + tot);
//    for(int i = 0; i < tot; i ++)
//        printf("%f\n", s[i]/4);
    double ans1 = max(log(s[0]) + log(0.5), log(s[tot - 1]) + log(0.5) * (tot - 1));
    int l = 0;
    while((1 << (l + 1)) <= tot) l ++;
    double ans2 = log(s[tot - 1]) + log(0.5) * l;
//    printf("%d --\n", l);
    if((1 << l) != tot)
    {
        ans2 = max(ans2, log(s[(1 << l) - 1]) + log(0.5) * (l - 1));
    }
    printf("%.6f\n", exp(min(ans1, ans2)));
}

int main()
{
    int T; scanf("%d", &T);
    while(T --)
    {
        scanf("%d", &n);
        for(int i = 0; i < n; i ++)
            scanf("%lf", &x[i]);
        solve();
    }
    return 0;
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:172056次
    • 积分:3655
    • 等级:
    • 排名:第8927名
    • 原创:177篇
    • 转载:11篇
    • 译文:0篇
    • 评论:40条
    最新评论