정규 대회 99 AtCoder

C - 최소화

다양한 옵션이있을 수 있습니다 첫 번째, 우리는 모든 옵션을 열거 한 다음 양쪽 욕심 얻을 수 있습니다.


암호

#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 번호

이 법을 찾을 수있는 테이블을 재생하는 것입니다 ...하지만 법이 쉽게 찾을 수없는, 법이 변화의 법칙은, 하나는 추가 할 수 있습니다 \ (10 ^ I \) , 당신은 또한 추가 할 수 있습니다 (10 \을 ^ {내가 + 1 } \ ) ,이 판단은 클릭합니다.


암호

#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 - 독립

문제의 의미
부여 \ (\ N-)\ (m의 \) 제 방향성 에지는 지금 두 점, 직접 최대 하나의 에지에 연결된다.
두 부분이 완료 그래프 것을, 마지막으로 가장 작은 각 부분의 측면 얼마의 몇 가지를 물었다 있도록이 이제도 두 부분으로 나누어 져 있습니다.

아이디어 :

  • 각각 포인트 양측 가정 웰이 계산 된 후 두 부분으로 나누어 답변 \ (X, Y의 \) A, 그 최종 응답이 (\를 \ FRAC {X \ cdot (X-1)} {2} + \ {Y FRAC \ CDOT. (1-Y)} {2} \) .
  • 이제 나누는 방법을 고려한다.
  • 우리는 그림의 원래 보완을, 다음 조건을 충족하는 모든 가장자리없이 마지막 두 세트는 존재한다.
  • 또한, 우리는이 분형 그래프의 동등한 것, 실제로 문제가 된 그래프 문제로 변환된다.
  • 먼저 각각의 블록은 두 개의 통신이 선택되어 있고, 우선, 통신을 복수의 블록이 있으면 된 그래프가 존재 하는지를 결정하고, 직접 배낭 \ (DP \) 리스트에있는 모든 프로그램의 최종 수를 얻었다에서.

(그리고 초기 I는 일차원 QAQ 롤링 할 생각)
다음과 같이 코드입니다 :


암호

#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 - 하드 기호를 먹는

작성하십시오.

추천

출처www.cnblogs.com/heyuhhh/p/11594640.html