2019.11.4 simulation game

T1 and the odd factor

Defined \ (F (n) \) of \ (n-\) largest singular factor, e.g. \ (F. (. 1) =. 1 \) , \ (F. (. 6) =. 3 \) , \ (F. (12 is) = 3 \) .
Input \ (m \) , seeking \ (\ SUM \ limits_. 1 {I} = {m} ^ F. (I) \) .
\ (m \ leq 10 ^ {
100} \) analyze, we found that if \ (I \) is an even number, \ (F. (I) = F. (I / 2) \) , so can partition prayed .
This problem difficult to write on a large high-precision high-precision, who exam ah

r = open('sigma.in','r')
w = open('sigma.out','w')
ans = 0
def sove(*t):
    global ans
    x = int(t[0])
    if x == 0:
        return None
    if x % 2 == 1:
        ans += (x + 1) * (x + 1) // 4
    else:
        ans += x *x // 4
    sove(x // 2)
n = r.read()
sove(n)
w.write(str(ans))

Of course, we can not seek recursion

r = open('sigma.in', 'r')
w = open('sigma.out', 'w')
ans=  0
n = int(r.read())
while(n != 0):
    if(n & 1):
        ans += (n + 1) * (n + 1) // 4
    else:
        ans += n * n // 4
    n //= 2
w.write(str(ans))

The following is a c ++ code. High Fey did not put too much.
High-precision class template

signed main()
{
    freopen("sigma.in", "r", stdin);
    freopen("sigma.out", "w", stdout);
    GNUM n;
    GNUM zero(0);
    cin >> n;
    GNUM ans(0);
    while (!(n == zero))
    {
        if (n.opd())
            ans = ans + (n + 1) * (n + 1) / 4;
        else
            ans = ans + n * n / 4;
        n = n / 2;
    }
    cout << ans << endl;
    return 0;
}

Array laser tower T2

Small strong consensus laser array column \ (P \) seat laser tower, which are built in a N $ \ Times M (on a rectangular grid. Each seat has its own coordinate laser tower \) \ (X, Y) \ (wherein \) X (. 1 \ Leq X \ n-Leq) \ (and \) Y (. 1 \ Leq Y \ Leq m) \ (are integers. when the two laser tower \) X \ (coordinates and \ ) Y \ (coordinates of at least one phase simultaneously, these two columns may have contact. If the laser column \) a \ (and \) B \ (associated, \) B \ (and \) C \ (also linked, it can be considered \) A \ (and \) C $ is also linked. But now laser tower does not necessarily twenty-two have contact, so he would like the new new laser tower making the two towers of both the laser has links.
You have to calculate and output Xiaoqiang how many laser tower requires a minimum of construction.
Obviously disjoint-set maintenance at a few communication block it.

int main()
{
    freopen("laser.in", "r", stdin);
    freopen("laser.out", "w", stdout);
    poread(n), poread(m), poread(p);
    for(register int i = 1; i <= p; ++i)
        poread(data[i].x), poread(data[i].y), data[i].id = i;
    for(register int i = 1; i <= p; ++i)
        fa[i] = i;
    sort(data + 1, data + 1 + p, cmp1);
    for(register int i = 2; i <= p; ++i)
    {
        if(data[i - 1].x == data[i].x)
        {
            register int x = find(data[i - 1].id), y = find(data[i].id);
            if(x == y)
                continue;
            fa[y] = x;
        }
    }
    sort(data + 1, data + 1 + p, cmp2);
    for(register int i = 2; i <= p; ++i)
    {
        if(data[i - 1].y == data[i].y)
        {
            register int x = find(data[i - 1].id), y = find(data[i].id);
            if(x == y)
                continue;
            fa[y] = x;
        }
    }
    register int ans = 0;
    for(register int i = 1; i <= p; ++i)
    {
        if(find(i) == i)
        {
            ++ans;
            
        }
    }
    printf("%d", ans - 1);
}

T3 Cronicas

This problem is a language problem letting go face the problem. Every time probably seek short-circuits are transferred from short-circuits.
Only put garbage thief slow running of \ (spfa \) a.

inline void sspfa()
{
    queue<int> q;
    memset(d, 0x3f, sizeof(d));
    memset(md, 0x3f, sizeof(md));
    for(register int i = 1; i <= k; ++i)
    {
        d[ek[i]] = md[ek[i]] = 0;
        g[ek[i]] = mg[ek[i]] = ek[i];
        q.push(ek[i]);
        v[ek[i]] = 1;
    }
    while(q.size())
    {
        register int x = q.front();
        q.pop();
        v[x] = 0;
        for(register int i = head[x]; i; i = e[i].nxt)
        {
            register int y = e[i].ver;
            if(d[y] > md[x] + e[i].edge)
            {
                if(g[y] != x)
                    md[y] = d[y], mg[y] = g[y];
                d[y] = md[x] + e[i].edge;
                g[y] = x;
                if(!v[y])
                    q.push(y), v[y] =  1;
            }
            else if(md[y] > md[x] + e[i].edge && g[y] != x)
            {
                md[y] = md[x] + e[i].edge;
                mg[y] = x;
                if(!v[y])
                    q.push(y), v[y] =  1;
            }
        }
    }
}

Guess you like

Origin www.cnblogs.com/Shiina-Rikka/p/11819212.html