AtCoder Regular Contest 99

Portal

C - Minimization

The first may have a variety of options, we enumerate all options, then both sides can get greedy.


Code

#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
//#define Local
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 5;

int n, k;

void run() {
    int p;
    for(int i = 1; i <= n; i++) {
        int x; cin >> x;
        if(x == 1) p = i;
    }
    int ans = N;
    for(int i = 1; i <= n; i++) {
        int l = i, r = min(n, i + k - 1);
        if(l <= p && p <= r)
            ans = min(ans, 1 + (l - 1 + k - 2) / (k - 1) + (n - r + k - 2) / (k - 1));
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
#ifdef Local
    freopen("../input.in", "r", stdin);
    freopen("../output.out", "w", stdout);
#endif
    while(cin >> n >> k) run();
    return 0;
}

D - Snuke Numbers

This is the playing table to find the law ... but the law is not easy to find, the law is the law of transformation, one might add \ (10 ^ i \) , you can also add \ (10 ^ {i + 1 } \ ) , two judgments click.


Code

#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define Local
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 5;

int K;

double Snuke(ll x) {
    ll tmp = 0, c = x;
    while(c) {
        tmp += c % 10;
        c /= 10;
    }
    return 1.0 * x / tmp;
}

void run() {
    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;
        cout << res << '\n';
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
#ifdef Local
    freopen("../input.in", "r", stdin);
    freopen("../output.out", "w", stdout);
#endif
    while(cin >> K) run();
    return 0;
}

E - Independence

The meaning of problems:
given \ (n-\) points \ (m \) Article undirected edges, for any two points now, directly connected to at most one edge.
To this figure is now divided into two parts, so that the two parts are complete graph, finally asked a few of the smallest side of each part and how much.

Ideas:

  • Answer divided into two parts after the well is calculated, assuming both sides respectively point \ (x, y \) a, then the final answer is \ (\ frac {x \ cdot (x-1)} {2} + \ {Y FRAC \ CDOT (. 1-Y)} {2} \) .
  • Now consider how to divide.
  • We take the original complement of drawing, then the final two sets without any edge that meet the conditions exist.
  • Further, we will be the equivalent of a bipartite graph, in fact, the problem will be converted into a bipartite graph problem.
  • First determines whether there is a bipartite graph, if there is, first, a plurality of communication blocks, each block has two communication is selected, the direct backpack \ (DP \) at obtain a final number of all programs on the list.

(And initially I thought capable of rolling one-dimensional QAQ)
code show as below:


Code

#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
//#define Local
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 705;
 
int n, m;
bool lnk[N][N];
int cnt[2];
int col[N];
bool f;
 
void dfs(int u, int c) {
    col[u] = c;
    ++cnt[c];
    for(int v = 1; v <= n; v++) {
        if(lnk[u][v]) {
            if(col[v] == -1) dfs(v, 1 - c);
            else if(col[v] == c) {
                f = false;
                return;
            }
        }
    }
}
 
pii num[N];
bool dp[N][N];
 
void run() {
    memset(col, -1, sizeof(col));
    memset(dp, 0, sizeof(dp));
    f = true;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++) {
            if(i != j) lnk[i][j] = 1;
        }
    for(int i = 1; i <= m; i++) {
        int u, v; cin >> u >> v;
        lnk[u][v] = lnk[v][u] = 0;
    }
    int tot = 0;
    for(int i = 1; i <= n; i++) {
        if(col[i] == -1) {
            cnt[0] = cnt[1] = 0;
            dfs(i, 0);
            num[++tot] = MP(cnt[0], cnt[1]);
        }
    }
    if(f == false) {
        cout << -1 << '\n';
        return;
    }
    dp[0][0] = 1;
    for(int i = 1; i <= tot; i++) {
        for(int j = 0; j <= n; j++) {
            if (j >= num[i].fi) dp[i][j] |= dp[i - 1][j - num[i].fi];
            if (j >= num[i].se) dp[i][j] |= dp[i - 1][j - num[i].se];
        }
    }
    int ans = 1e9;
    for(int i = 0; i <= n; i++) {
        if(dp[tot][i]) {
            ans = min(ans, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2);
        }
    }
    cout << ans << '\n';
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
#ifdef Local
    freopen("../input.in", "r", stdin);
    freopen("../output.out", "w", stdout);
#endif
    while(cin >> n >> m) run();
    return 0;
}

F - Eating Symbols Hard

To be completed.

Guess you like

Origin www.cnblogs.com/heyuhhh/p/11594640.html