题解

3 条题解

  • 0
    @ 2016-03-18 07:53:26

    #include<cstdio>
    #include<cstring>
    #include<algorithm>

    using namespace std;

    const int maxn = 20009;

    int a[maxn], t, n, d, tot;
    int p[maxn], pn, cnt0[maxn], cnt1[maxn];
    bool F[maxn];

    void Init() {
    memset(F, 0, sizeof F);
    pn = 0;
    for(int i = 2; i < maxn; i++) {
    if(!F[i])
    p[pn++] = i;
    for(int j = 0; i * p[j] < maxn; j++) {
    F[i * p[j]] = true;
    if(i % p[j] == 0) break;
    }
    }
    }

    int buf[10000];
    void calc(int h[]) {
    memset(buf, 0, sizeof buf);
    buf[0] = 1;
    int L = 1;
    for(int i = 0; i < pn; i++)
    for(int j = 0; j < h[i]; j++) {
    for(int k = 0; k < L; k++) buf[k] *= p[i];
    for(int k = 0; k < L; k++) if(buf[k] > 9) {
    buf[k + 1] += buf[k] / 10;
    buf[k] %= 10;
    }
    for(; buf[L] > 0; L++) if(buf[L] > 9) {
    buf[L + 1] += buf[L] / 10;
    buf[L] %= 10;
    }
    }
    while(L--)
    putchar(buf[L] + '0');
    }

    void mult(int x, int h[]) {
    for(int i = 0; i < pn; i++) if(x % p[i] == 0)
    for(; x % p[i] == 0; x /= p[i]) h[i]++;
    }

    int main() {

    Init();
    scanf("%d%d%d", &t, &n, &d);
    for(int i = 1; i <= t; i++) {
    scanf("%d", a + i);
    tot += a[i];
    }
    while(n--) {
    int x, y;
    scanf("%d%d", &x, &y);
    mult(a[y], cnt0);
    mult(tot, cnt1);
    tot += d, a[y] += d;
    }
    for(int i = 0; i < pn; i++) if(cnt1[i] >= cnt0[i])
    cnt1[i] -= cnt0[i], cnt0[i] = 0;
    else if(cnt1[i] < cnt0[i])
    cnt0[i] -= cnt1[i], cnt1[i] = 0;
    calc(cnt0);
    putchar('/');
    calc(cnt1);

    return 0;
    }

  • 0
    @ 2015-09-04 21:11:19

    沙发

  • 1

信息

ID
1833
难度
3
分类
(无)
标签
递交数
47
已通过
25
通过率
53%
被复制
2
上传者