Codeforces 라운드 # 598 (사업부. 3)

변경없이 A. 지불

로그인합니다.


암호

/*
 * Author:  heyuhhh
 * Created Time:  2019/11/4 21:19:19
 */
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << '\n'; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
#else
  #define dbg(...)
#endif
void pt() {std::cout << '\n'; }
template<typename T, typename...Args>
void pt(T a, Args...args) {std::cout << a << ' '; pt(args...); }
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5;
 
int a, b, n, S;
 
void run(){
    cin >> a >> b >> n >> S;
    ll r = S - 1ll * a * n;
    if(r <= 0) r = S % n;
    if((ll)b >= r) pt("YES");
    else pt("NO");
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    int T; cin >> T;
    while(T--) run();
    return 0;
}

B.는 순열을 최소화

문제의 의미
소정 . (1 \) \을 ~ \ (N- \) 배치, 현재 위치에 대한 \ (I는 \) , 교환 할 수 \ (A_I, + {I는 \ A_ 1}.) . 그러나 각 위치 만 교환 한 번 교환 할 수있다 충족 \ (N-1 \) 번.
출력 동작 후의 전적으로 작은 시퀀스.

아이디어 :
각 위치의 뒷면이 지속적으로 욕심 간주 될 수 있습니다에서 직접.
각 교환은 적어도 한 번 시퀀스를 통해 청소되므로 복잡도는 \ (O (N ^ -2) \) .


암호

/*
 * Author:  heyuhhh
 * Created Time:  2019/11/4 21:26:23
 */
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << '\n'; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
#else
  #define dbg(...)
#endif
void pt() {std::cout << '\n'; }
template<typename T, typename...Args>
void pt(T a, Args...args) {std::cout << a << ' '; pt(args...); }
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 105;
 
int n;
int a[N];
bool chk[N];
 
void run(){
    cin >> n;
    int p;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    memset(chk, 0, sizeof(chk));
    int cnt = 0;
    while(1) {
        cnt = 0;
        for(int i = n - 1; i >= 1; i--) {
            if(chk[i]) continue;
            if(a[i + 1] < a[i]) {
                swap(a[i + 1], a[i]), ++cnt;
                chk[i] = 1;
            }
        }
        if(!cnt) break;
    }
    for(int i = 1; i <= n; i++) cout << a[i] << " \n"[i == n];
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    int T; cin >> T;
    while(T--) run();
    return 0;
}

C. 플랫폼 점프

이탈리아 그건 :
에있는 한 \ (0 \) 수의 위치, 그리고 지금 뛰어 \ (N + 1 \) 각 점프에서 번호 위치 \을 (X는 \) 로 점프 \ (1 + X \.) ~ \ ( D + X \) .
을 감안할 때 \ (m의 \) 나무의 블록의 길이, 당신이 것을 주선 (m의 \) \ 나무 블록의 위치 (상대 순서를 변경하고 중복되지 수 없음), 마지막으로 프로그램의 출력, 또는 사람이 성공적으로 할 수 없다 \ ( N + 1 \) 포인트.

아이디어 :

  • 직접 욕심 판사의 타당성을 결정, 이상적인 경우에이 시간,이 사람은 가장 멀리까지 이동할 수 있습니다;
  • 특정 실시 예에서, 판자의 세트의 총 길이를 고려할 때 \ (L의 \)을 하고있다 \ (거리 nL \) 공극의 공극이 너무 오래도 너무 짧게 될 수 없다.
  • 따라서, 판자 될 수 넣어 직접 그리 갭이 방법.

코드를 참조하십시오 :


암호

/*
 * Author:  heyuhhh
 * Created Time:  2019/11/4 22:07:56
 */
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << '\n'; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
#else
  #define dbg(...)
#endif
void pt() {std::cout << '\n'; }
template<typename T, typename...Args>
void pt(T a, Args...args) {std::cout << a << ' '; pt(args...); }
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1005;
 
int n, m, d;
int c[N];
int a[N], ans[N];
 
void run(){
    cin >> n >> m >> d;
    int tot = 0;
    for(int i = 1; i <= m; i++) cin >> c[i], tot += c[i];
    int s = 0;
    for(int i = 1; i <= m; i++) {
        s += d + c[i] - 1;
    }
    s += d;
    if(s < n + 1) {
        cout << "NO" << '\n';
        return ;
    }
    pt("YES");
    int r = n - tot;
    s = 0;
    for(int i = 1; i <= m; i++) {
        int t = min(r , d - 1);
        r -= t;
        s += t + 1;
        a[s] = i;
        s += c[i] - 1;
    }
    for(int i = 1, j; i <= n; i = j + 1) {
        j = i;
        if(a[i]) {
            for(; j <= i + c[a[i]] - 1; j++) ans[j] = a[i];
            --j;
        }
    }
    for(int i = 1; i <= n; i++) cout << ans[i] << " \n"[i == n];
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}

D. 진 문자열 최소화

문제의 의미 :
주어진 \ (01 \) 교환의 두 개의 연속 된 문자 위치 : 문자열, 지금 하나 개의 작업을 수행합니다.
실행하도록 \ (K \) 연산 전적으로 작은 결과 출력 문자열.

생각 :
\ (0 \) 라인에 순차적 순방향 욕심 이동, 상기 항 (1 \) \의 프로그램 출력의 수.


암호

/*
 * Author:  heyuhhh
 * Created Time:  2019/11/4 21:43:49
 */
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << '\n'; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
#else
  #define dbg(...)
#endif
void pt() {std::cout << '\n'; }
template<typename T, typename...Args>
void pt(T a, Args...args) {std::cout << a << ' '; pt(args...); }
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e6 + 5;
 
int n;
ll k;
char s[N];
int sum[N], has[N];
 
void run(){
    cin >> n >> k;
    cin >> (s + 1);
    int tot = 0;
    for(int i = 0; i <= n; i++) has[i] = 0;
    for(int i = 1; i <= n; i++) {
        sum[i] = sum[i - 1];
        if(s[i] == '1') ++sum[i], ++tot;
        else {
            ++has[sum[i]];
        }
    }
    for(int i = 1; i <= n && k; i++) if(s[i] == '0') {
        if((ll)sum[i] <= k) {
            --has[sum[i]];
            ++has[0];
            k -= sum[i];
        }   
        else {
            --has[sum[i]];
            sum[i] -= k;
            ++has[sum[i]];
            k = 0;
        }
    }
    int cnt = 0;
    while(cnt < tot) {
        while(has[cnt]--) cout << 0;
        cout << 1;
        ++cnt;
    }
    while(has[cnt]--) cout << 0;
    cout << '\n';
}  
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    int T; cin >> T;
    while(T--) run();
    return 0;
}

E. 또 다른 부문 속으로 팀

질문의 의미 :
합니다 (N \) \ 최대 값을 뺀 최소로 각 세트의 학생 그룹, "가치".
지금은 "값"마지막으로 모든 그룹을 요청하고 최소 수에 대한 각 그룹에서 적어도 세 학생들이 필요합니다.

아이디어 :

  • 분명히 학생들의 응답에 영향을주지 않습니다 순서, 당신은 순서를 행 할 수 있습니다.
  • 즉 단순한 패킷 후 \는 (DP : DP [I]가 \) 전면 나타내는 \ (나는 \) 개인 작은 그룹으로 응답하도록한다. 열거 앞에 전사 \ (j의 \) 옮겼다.
  • \ (O (N ^ 2) \) 물론, 앞의 검색된 여유가 없다 \ (DP \) 값이 확실히 최소 선택하므로 우선 순위 큐를 유지하기 위해 사용.

세부 사항 중 일부는 세부 사항이 코드를 볼 수 있습니다 :


암호

/*
 * Author:  heyuhhh
 * Created Time:  2019/11/5 9:03:50
 */
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << '\n'; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
#else
  #define dbg(...)
#endif
void pt() {std::cout << '\n'; }
template<typename T, typename...Args>
void pt(T a, Args...args) {std::cout << a << ' '; pt(args...); }
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 2e5 + 5;
 
int n;
struct node{
    ll v;
    int id;
    bool operator < (const node &A) const{
        return v > A.v;
    }
}a[N];
 
ll dp[N];
int ans[N], tmp[N], from[N];
 
 
void run(){
    memset(from, 0, sizeof(from));
    memset(tmp, 0, sizeof(tmp));
    for(int i = 1; i <= n; i++) {
        cin >> a[i].v; a[i].id = i;
    }
    a[n + 1] = node{0, 0};
    sort(a + 1, a + n + 1, [&](node A, node B) {
        return A.v < B.v;
    });
    priority_queue <node> q;
    dp[0] = -a[1].v;
    q.push(node{dp[0], 0});
    for(int i = 1; i <= n; i++) {
        vector <node> vec(4);
        while(!q.empty()) {
            node now = q.top(); q.pop();
            vec.push_back(now);
            if(i - now.id >= 3) {
                dp[i] = now.v + a[i].v - a[i + 1].v;
                q.push(node{dp[i], i});
                from[i] = now.id;
                break;
            } 
        }
        for(auto it : vec) q.push(it);
    }
    int p = n;
    while(p) {
        tmp[from[p] + 1] = 1;
        p = from[p];        
    }
    for(int i = 1; i <= n; i++) tmp[i] += tmp[i - 1];
    cout << dp[n] << ' ' << tmp[n] << '\n';
    for(int i = 1; i <= n; i++) ans[a[i].id] = tmp[i];
    for(int i = 1; i <= n; i++) cout << ans[i] << " \n"[i == n];
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    while(cin >> n) run();
    return 0;
}

F. 두 문자열 동점 골

문제의 의미 :
문자열이 동일한 쿼리가 결국 문자열이 될 수있는 반면 두 문자열 부여는 두 문자열은 이제 여러 번 같은 길이를 인계 할 수 있습니다.

아이디어 :

  • 당신은 여러 번 뒤집어 수 있기 때문에, 다음 어느 시간 플립, 우리는 이상에 해당 될 수있다 \ (스왑 \) 작업. 그런 다음 우리는 길이 고려 \ (2 \) 뒤집기 작업을.
  • 두 문자열의 문자 먼저 제외 특정 번호가 동일하지 않습니다.
  • 그것은 찾을 수 있습니다 경우 \ (t의 \) 문자열과 두 개의 연속 된 동일 문자, 몇 가지 법률이 있습니다. 이 두 문자열의 지속적인 교환은 모양을 변경하지 않기 때문에.
  • 또한 추론 : 경우 \ (t의 \)는 문자가 하나 이상의 문자열 발생합니다 \ (1 \) 번, 그것은 합법적이다.
  • 만 길이가 초과하지 않는 생각 \ (26 \) 상황. 이제 판사의 \을 (\) 문자열로 이동할 수 있습니다 \ (t의 \) 문자열, 우리는 심지어 법적 또는 불법 인 경우, 두 패리티의 수는 차이가있을 수 있습니다 반대로 볼 필요는 없다.

뇌의 정확성은 더 잘 이해되어야한다 만들 ...


암호

/*
 * Author:  heyuhhh
 * Created Time:  2019/11/4 22:38:32
 */
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << '\n'; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
#else
  #define dbg(...)
#endif 
void pt() {std::cout << '\n'; } template<typename T, typename...Args>
  void pt(T a, Args...args) {std::cout << a << ' '; pt(args...); } using
  namespace std; typedef long long ll; typedef pair<int, int> pii;
//head
const int N = 2e5 + 5;
 
int n; char s[N], t[N];
int cnt[2][26];
int c1[N], c2[N];
 
void run(){
    cin >> n;
    cin >> (s + 1) >> (t + 1);
    for(int i = 0; i < 26; i++) {
        cnt[0][i] = cnt[1][i] = 0;
    }
    for(int i = 1; i <= n; i++) ++cnt[0][s[i] - 'a'];
    for(int i = 1; i <= n; i++) ++cnt[1][t[i] - 'a'];
    for(int i = 0; i < 26; i++) if(cnt[0][i] != cnt[1][i]) {
        pt("NO"); return; 
    }
    for(int i = 0; i < 26; i++) if(cnt[1][i] > 1) {
        pt("YES"); return;
    }
    int d = 0;
    for(int i = 1; i <= n; i++) 
        for(int j = i + 1; j <= n; j++) {
            if(s[j] - '0' < s[i] - '0') ++d;
            if(t[j] - '0' < t[i] - '0') --d;
        }
    if(d & 1) pt("NO");
    else pt("YES");
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    int T; cin >> T;
    while(T--) run();
    return 0;
}

추천

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