| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2731 人关注过本帖
标题:求助帖,脑壳秃了........
取消只看楼主 加入收藏
java小白兔
Rank: 1
等 级:新手上路
帖 子:29
专家分:3
注 册:2018-11-7
结帖率:100%
收藏
已结贴  问题点数:80 回复次数:0 
求助帖,脑壳秃了........
图片附件: 游客没有浏览图片的权限,请 登录注册
图片附件: 游客没有浏览图片的权限,请 登录注册

这是我字自己写的代码,错误有点多,求大佬指正!!!!!
public class Main {
    const int MAXN = 1e5 + 10;
    LL INF = 2e9 + 10, B = 20;
    inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
    }
    int N, jp[MAXN][21], nxa[MAXN], nxb[MAXN], flag[MAXN], h[MAXN];
    LL f[MAXN][21], da[MAXN][21], db[MAXN][21];
    struct Node {
    LL Hi, id;
    bool operator < (const Node &rhs) const{
        return Hi == rhs.Hi ? h[id] < h[rhs.id] : Hi < rhs.Hi;
        }
    };
    int get(int x, int y) {
    return abs(h[x] - h[y]);
    }
    set<Node> s;
    void Pre() {
    s.insert((Node) {-INF * 2, 0}); s.insert((Node) {INF * 2, 0});
    s.insert((Node) {-INF * 2 + 1, 0}); s.insert((Node) {INF * 2 + 1, 0});
    s.insert((Node) {h[N], N});
    memset(f, 0x3f, sizeof(f));
    for(int i = N - 1; i >= 1; i--) {
        set<Node> :: iterator y = s.lower_bound((Node) {h[i], i});
        vector<Node> tmp; tmp.clear();
        tmp.push_back((Node) {get(y -> id, i), y -> id}); y++;
        tmp.push_back((Node) {get(y -> id, i), y -> id}); y--; y--;
        tmp.push_back((Node) {get(y -> id, i), y -> id}); y--;
        tmp.push_back((Node) {get(y -> id, i), y -> id});
        sort(tmp.begin(), tmp.end());
        nxa[i] = tmp[1].id;
        nxb[i] = tmp[0].id;
        s.insert((Node) {h[i], i});
        if(tmp[1].id != 0 && tmp[0].id != 0) f[i][0] = tmp[1].Hi + db[tmp[1].id][0];
        jp[i][0] = nxb[nxa[i]];
        da[i][0] = get(i, nxa[i]);
        db[i][0] = get(i, nxb[i]);
    }
    for(int j = 1; j <= B; j++)
        for(int i = 1; i <= N; i++) {
            if(jp[i][j - 1])
                jp[i][j] = jp[jp[i][j - 1]][j - 1],
                f[i][j] = f[i][j - 1] + f[jp[i][j - 1]][j - 1],
                da[i][j] = f[i][j] == INF ? 0 : da[i][j - 1] + da[jp[i][j - 1]][j - 1];     
        }

}
        void print() {
        for(int i = 1; i <= N; i++) printf("**%d\n", f[i][0]);
    }
        Pair Query(int pos, int val) {
            LL a1 = 0, a2 = 0;
        for(int i = B; ~i; i--)
        if(f[pos][i] <= val)
            val -= f[pos][i], a1 += da[pos][i], a2 += f[pos][i] - da[pos][i], pos = jp[pos][i];
    if(da[pos][0] <= val) a1 += da[pos][0];
    return MP(a1, a2);   
}
signed main() {
   // freopen("drive3.in", "r", stdin);
 //   freopen("a.out", "w", stdout);
    N = read();
    for(int i = 1; i <= N; i++) h[i] = read(); h[0] = INF;

    Pre();
   // print();
    int X0 = read(), ans = N;
    double tmp = 1e22;
    for(int i = 1; i <= N; i++) {
        Pair now = Query(i, X0);
        if(now.se == 0) continue;
        if((double)now.fi / now.se < tmp) tmp = (double)now.fi / now.se, ans = i;
    }
    printf("%d\n", ans);
    int M = read();
    while(M--) {
        int Si = read(), Mi = read();
        Pair now = Query(Si, Mi);
        printf("%d %d\n", now.fi, now.se);
    }
    return 0;
}
}
搜索更多相关主题的帖子: int read get Node tmp 
2018-11-19 13:47
快速回复:求助帖,脑壳秃了........
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016652 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved