群赛12----2017.9.24

T1 Jzzhu and Children

题意:

给你一串字符串,由原字符串不断取中位数组成,请还原原字符串.

解法:

暴力.

代码:

#include <bits/stdc++.h>
using namespace std;
int x[1000000][2];
int main()
{
    int a, b, tou = 1, wei;
    cin >> a >> b;
    for (int i = 1; i <= a; i++)
    {
        cin >> x[i][1];
        x[i][2] = i;
    }
    wei = a;
    while (tou != wei)
    {
        x[tou][1] -= b;
        if (x[tou][1] <= 0)
        {
            tou++;
            a--;
        }
        else
        {
            x[wei + 1][1] = x[tou][1];
            x[wei + 1][2] = x[tou][2];
            tou++;
            wei++;
        }
    }
    cout << x[tou][2];
    return 0;
}

网址:这一题

小结:

**此类题目水题。**

T2 Jzzhu and Sequences

题意:

给出一种规律,输出第几个.

解法:

暴力.

代码:

#include <bits/stdc++.h>
using namespace std;
#define N 1000000007
long long x[100];
int main()
{
    long long a, b, ans, c;
    cin >> x[1] >> x[2] >> ans;
    x[3] = x[2] - x[1];
    c = ans / 3;
    if (c % 2 == 0)
    {
        c = ans % 3;
        if (c == 0)
        {
            ans = -x[3];
        }
        if (c == 1)
        {
            ans = x[1];
        }
        if (c == 2)
        {
            ans = x[2];
        }
    }
    else
    {
        c = ans % 3;
        if (c == 0)
        {
            ans = x[3];
        }
        if (c == 1)
        {
            ans = -x[1];
        }
        if (c == 2)
        {
            ans = -x[2];
        }
    }
    while (ans < 0)
        ans += N;
    cout << ans % N;
    return 0;
}

网址:这一题

小结:

**此类题目暴力。**

T3 Jzzhu and Chocolate

题意:

给出一个n*m的蛋糕,切几刀,问最小块的最大值是多少.

解法:

暴力优化。

代码:

#include <bits/stdc++.h>
using namespace std;

int main()
{
    long long n, m, k;
    cin >> n >> m >> k;
    if (n < m)
        swap(n, m);
    if (k > n - 1 + m - 1)
        cout << -1;
    else
    {
        if (k <= m - 1)
        {
            long long ans = 1, s1, s2, max6;
            ans = n / (k + 1);
            s1 = ans * m;
            ans = m / (k + 1);
            s2 = ans * n;
            max6 = max(s1, s2);
            cout << max6;
        }
        else if (k <= n - 1)
        {
            long long ans = 1, s1;
            ans = n / (k + 1);
            s1 = ans * m;
            cout << s1;
        }
        else
        {
            k = k - n + 1;
            long long ans = 1;
            ans = m / (k + 1);
            cout << (ans);
        }
    }
    return 0;
}

网址:这一题

小结:

**此类题目暴力。**

T4 Jzzhu and Cities

题意:

给你几个城市,城市之间有几条路,有些城市有到首都的铁路,如果某个市到首都的路要经过铁路,那么这个铁路就不能拆去,问最少可以拆几个铁路.

解法:

wu

代码:

#include <bits/stdc++.h>
#define ll long long
#define M 1000000000000000000
#define N 100005
using namespace std;
ll n, m, K, p[N], vis[N], d[N];
vector<pair<int, int> > g[N];
queue<int> que;
int main()
{
    int u, v, x, i;
    scanf("%d%d%d", &n, &m, &K);
    for (i = 0; i < m; i++)
    {
        scanf("%d%d%d", &u, &v, &x);
        g[u].push_back(make_pair(v, x));
        g[v].push_back(make_pair(u, x));
    }
    for (i = 0; i <= n; i++)
        d[i] = M;
    d[1] = 0;
    memset(p, 0, sizeof(p));
    vis[1] = 1;
    que.push(1);
    for (i = 1; i <= K; i++)
    {
        scanf("%d%d", &u, &x);
        if (d[u] > x)
        {
            d[u] = x;
            p[u] = 1;
            if (vis[u] == 0)
            {
                vis[u] = 1;
                que.push(u);
            }
        }
    }
    while (!que.empty())
    {
        u = que.front();
        que.pop();
        vis[u] = 0;
        for (i = 0; i < g[u].size(); i++)
        {
            v = g[u][i].first, x = g[u][i].second;
            if (d[v] >= d[u] + x && p[v] != 0)
                p[v] = 0;
            if (d[v] > d[u] + x)
            {
                d[v] = d[u] + x;
                if (vis[v] == 0)
                {
                    vis[v] = 1;
                    que.push(v);
                }
            }
        }
    }
    for (i = 1; i <= n; i++)
        K -= p[i];
    cout << K;
    return 0;
}

网址:这一题

小结:

**此类题目较难。**

T5 Jzzhu and Apples

题意:

把n个数1-n分成几份,每份必须不互质,问最多分成几份.

解法:

根据题意写就行了,找规律。

代码:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int ggg[maxn];
int ans, n;
bool hhh(int x)
{
    bool mark = true;
    for (int i = 2; i * i <= x; i++)
        if (x % i == 0)
            mark = false;
    return mark;
}
int main()
{
    cin >> n;
    memset(ggg, -1, sizeof ggg);
    for (int i = (n / 2); i > 1; i--)
        if (hhh(i))
        {
            vector<int> v;
            for (int j = i; j <= n; j += i)
                if (ggg[j] == -1)
                    v.push_back(j);
            if ((int)v.size() % 2 == 0)
                for (int j = 0; j < (int)v.size(); j += 2)
                {
                    ggg[v[j]] = v[j + 1];
                    ggg[v[j + 1]] = v[j];
                    ans++;
                }
            else if (v.size() > 2)
            {
                ggg[v[0]] = v[2];
                ggg[v[2]] = v[0];
                ans++;
                for (int j = 3; j < (int)v.size(); j += 2)
                {
                    ggg[v[j]] = v[j + 1];
                    ggg[v[j + 1]] = v[j];
                    ans++;
                }
            }
        }
    cout << ans << endl;
    for (int i = 1; i <= n; i++)
        if (ggg[i] > i)
            cout << i << ' ' << ggg[i] << endl;
    return 0;
}

网址:这一题

小结:

**此类题目较难。**
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值