BestCoder Round #35

01:枚举每个位置,求出期望,累加起来就是答案,注意最后要约分

02:这题居然被我用优先队列瞎搞过了,估计是数据水了,正解是要用线段树,做一个拓扑排序的时候,每次取出当前节点中,度数小于等于k的,下标最大的点,这个用线段树很好维护

代码:

01:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;

int n, m;

ll C(int n, int m) {
    m = min(n - m, m);
    ll ans = 1;
    for (int i = 0; i < m; i++) {
        ans = ans * (n - i) / (i + 1);
    }
    return ans;
}

ll gcd(ll a, ll b) {
    if (!b) return a;
    return gcd(b, a % b);
}

int main() {
    while (~scanf("%d%d", &n, &m)) {
        ll zi = 0, mu;
        mu = C(n + m, n);
        for (int i = 0; i < n + m - 1; i++) {
            zi += C(n + m - 2, n - 1);
        }
        ll d = gcd(zi, mu);
        printf("%I64d/%I64d\n", zi / d, mu / d);
    }
    return 0;
}

02:

#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

const int N = 100005;

int n, m, k, du[N];
vector<int> g[N];

#define lson(x) ((x<<1)+1)
#define rson(x) ((x<<1)+2)

const int INF = 0x3f3f3f3f;

struct Node {
    int l, r, Min;
} node[N * 4];

void build(int l, int r, int x = 0) {
    node[x].l = l; node[x].r = r; node[x].Min = INF;
    if (l == r) return;
    int mid = (l + r) / 2;
    build(l, mid, lson(x));
    build(mid + 1, r, rson(x));
}

void add(int v, int val, int x = 0) {
    if (node[x].l == node[x].r) {
        node[x].Min = val;
        return;
    }
    int mid = (node[x].l + node[x].r) / 2;
    if (v <= mid) add(v, val, lson(x));
    else add(v, val, rson(x));
    node[x].Min = min(node[lson(x)].Min, node[rson(x)].Min);
}

int find(int v, int x = 0) {
    if (node[x].l == node[x].r)
        return node[x].l;
    if (node[rson(x)].Min <= v) return find(v, rson(x));
    return find(v, lson(x));
}

int main() {
    while (~scanf("%d%d%d", &n, &m, &k)) {
        int u, v;
        for (int i = 1; i <= n; i++) {
            du[i] = 0;
            g[i].clear();
        }
        while (m--) {
            scanf("%d%d", &u, &v);
            g[u].push_back(v);
            du[v]++;
        }
        build(1, n);
        for (int i = 1; i <= n; i++)
            add(i, du[i]);
        int bo = 0;
        for (int i = 0; i < n; i++) {
            int u = find(k);
            if (bo) printf(" ");
            else bo = 1;
            printf("%d", u);
            k -= du[u];
            du[u] = INF;
            add(u, du[u]);
            for (int i = 0; i < g[u].size(); i++) {
                int v = g[u][i];
                du[v]--;
                add(v, du[v]);
            }
        }
        printf("\n");
    }
    return 0;
}
时间: 2024-10-06 08:46:04

BestCoder Round #35的相关文章

hdu 5195 DZY Loves Topological Sorting BestCoder Round #35 1002 [ 拓扑排序 + 优先队列 || 线段树 ]

传送门 DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 221    Accepted Submission(s): 52 Problem Description A topological sort or topological ordering of a directed

HDU-5194-DZY Loves Balls(BestCoder Round # 35 )

DZY Loves Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 374    Accepted Submission(s): 205 Problem Description There are n black balls and m white balls in the big box. Now, DZY starts

BestCoder Round #35(DZY Loves Topological Sorting-堆+贪心)

DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 323    Accepted Submission(s): 86 Problem Description A topological sort or topological ordering of a directed gr

BestCoder Round #35(DZY Loves Balls-暴力dp)

DZY Loves Balls Accepts: 371 Submissions: 988 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Description There are n  black balls and m  white balls in the big box. Now, DZY starts to randomly pick out the ba

BestCoder Round #4 前两题 hdu 4931 4932

第一题太水了.. 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 int a[6]; 7 int main(){ 8 int cas; 9 scanf( "%d", &cas ); 10 while( cas-- ){ 11 for( int i = 0; i <

BestCoder Round #88

传送门:BestCoder Round #88 分析: A题统计字符串中连续字串全为q的个数,预处理以下或加个cnt就好了: 代码: 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <ctime> 5 #include <cmath> 6 #include <iostream> 7 #include <algorithm> 8

BestCoder Round #29——A--GTY&#39;s math problem(快速幂(对数法))、B--GTY&#39;s birthday gift(矩阵快速幂)

GTY's math problem Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0 Problem Description GTY is a GodBull who will get an Au in NOI . To have more time to learn alg

BestCoder Round #2 1001 (简单处理)

题目链接 题意:给N条信息,每个信息代表有x个人从开始的时间 到 结束的时间在餐厅就餐, 问最少需要多少座位才能满足需要. 分析:由于时间只有24*60 所以把每个时间点放到 数组a中,并标记开始的时间+x, 结束的时间 -x.最后累加比较. 如果时间点太多的时候可以把时间点放到结构体里,排序,然后依次枚举结构体. 1 #include <iostream> 2 #include <cstring> 3 #include <cstdlib> 4 #include <

从lca到树链剖分 bestcoder round#45 1003

bestcoder round#45 1003 题,给定两个点,要我们求这两个点的树上路径所经过的点的权值是否出现过奇数次.如果是一般人,那么就是用lca求树上路径,然后判断是否出现过奇数次(用异或),高手就不这么做了,直接树链剖分.为什么不能用lca,因为如果有树退化成链,那么每次询问的复杂度是O(n), 那么q次询问的时间复杂度是O(qn) 什么是树链剖分呢? 就是把树的边分成轻链和重链 http://blogsina.com.cn/s/blog_6974c8b20100zc61.htmlh