Atcoder Regular 099 暴力区间扩张 n/dig(n)极值打表 团分割背包

C

直接把第一次加在哪里for一遍即可

/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int dir[8][2] = {{0, 1}, {1, 0}, {0, -1}, { -1, 0}, {1, 1}, {1, -1}, { -1, -1}, { -1, 1}};
const int mod = 1e9 + 7, gakki = 5 + 2 + 1 + 19880611 + 1e9;
const int MAXN = 2e5 + 5, MAXM = 2e5 + 5, N = 2e5 + 5;
const int MAXQ = 100010;
/*int to[MAXM << 1], nxt[MAXM << 1], Head[MAXN], tot = 1;
inline void addedge(int u, int v)
{
        to[++tot] = v;
        nxt[tot] = Head[u];
        Head[u] = tot;
}*/
inline void read(int &v)
{
        v = 0;
        char c = 0;
        int p = 1;
        while (c < '0' || c > '9')
        {
                if (c == '-')
                {
                        p = -1;
                }
                c = getchar();
        }
        while (c >= '0' && c <= '9')
        {
                v = (v << 3) + (v << 1) + c - '0';
                c = getchar();
        }
        v *= p;
}
int num[100005];
int main()
{
        int n;
        int k;
        int minn = INT_MAX;
        int aim;
        read(n), read(k);
        for (int i = 1; i <= n; i++)
        {
                read(num[i]);
                if (num[i] < minn)
                {
                        minn = num[i];
                        aim = i;
                }
        }
        int ans = 0;
        ans = INT_MAX;
        int anser = 0;
        for (int laim = max(1, aim - k + 1); laim <= aim; laim++)
        {
                int raim = min(n, laim + k - 1);
                anser = 1;
                if ((laim - 1) % (k - 1))
                {
                        anser++;
                }
                anser += (laim - 1) / (k - 1);
                if ((n - raim) % (k - 1))
                {
                        anser++;
                }
                anser += (n - raim) / (k - 1);
                ans = min(ans, anser);
        }
        cout << ans << endl;
        return 0;
}
View Code

正解:

    scanf("%d%d",&n,&k);
    printf("%d\n",(n-2)/(k-1)+1);

(直接(n-1)/(k-1)向上取整即可 感觉自己是个弱智

D

打表找规律

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
double Snuke(ll x)
{
        ll tmp = 0, c = x;
        while (c)
        {
                tmp += c % 10;
                c /= 10;
        }
        return 1.0 * x / tmp;
}
int main()
{
        int K;
        cin >> K;
        ll res = 0, x = 1;
        while (K--)
        {
                double t1, t2;
                while (true)
                {
                        t1 = Snuke(res + x), t2 = Snuke(res + x * 10);
                        if (t1 <= t2)
                        {
                                break;
                        }
                        x *= 10;
                }
                res += x;
                printf("%lld\n", res);
        }
        return 0;
}
View Code

E

背包

posted @ 2018-06-25 20:03  Aragaki  阅读(230)  评论(0编辑  收藏  举报