CodeForces Round #567 Div.2

A. Chunga-Changa

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

long long x, y, z;

int main() {
    long long ans = 0, cnt = 0;
    scanf("%lld%lld%lld", &x, &y, &z);
    ans = (x + y) / z;
    long long p1 = x % z, p2 = y % z;
    if(z - p1 < z - p2) {
        if(p2 >= z - p1) cnt = z - p1;
    } else {
        if(p1 >= z - p2) cnt = z - p2;
    }
    printf("%lld %lld\n", ans, cnt);
    return 0;
}
View Code

B. Split a Number

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

int N;
string s, ans, temp;

string add(string a, string b) {
    string c;
    int len1 = a.length();
    int len2 = b.length();
    int len = max(len1, len2);
    for(int i = len1; i < len; i ++)
        a = "0" + a;
    for(int i = len2; i < len; i ++)
        b= "0" + b;
    int ok = 0;
    for(int i = len - 1; i >= 0; i --) {
        char temp = a[i] + b[i] - '0' + ok;
        if(temp > '9') {
            ok = 1;
            temp -= 10;
        }
        else ok = 0;
        c = temp + c;
    }
    if(ok) c = "1" + c;
    return c;
}

string DelZero(string t) {
    string ans = "";
    int temp = 0;
    for(int i = 0; t[i]; i ++) {
        if(t[i] != '0') {
            temp = i;
            break;
        }
    }
    ans = t.substr(temp, t.length() - temp);
    return ans;
}

string Sum(int x) {
    string num1 = s.substr(0, x);
    string num2 = s.substr(x, N - x);
    string ans = add(num1, num2);
    return ans;
}

bool Bigger(string &a, string &b) {
    if(a.length() > b.length()) return true;
    else if(a.length() < b.length()) return false;
    else {
        int len = a.length();
        for(int i = 0; i < len; i ++) {
            if(a[i] == b[i]) continue;
            if(a[i] > b[i]) return true;
            return false;
        }
    }
}

int main() {
    scanf("%d", &N);
    cin >> s;

    ans = s;

    int pos = (N - 1) / 2, p = pos;
    int cnt = 0;
    while(p >= 0 && cnt <= 1) {
        if(s[p + 1] != '0') {
            temp = Sum(p + 1);
            if(Bigger(ans, temp)) ans = temp;
            cnt ++;
        }
        p --;
    }
    p = pos;

    cnt = 0;
    while(p < N - 1 && cnt <= 0) {
        if(s[p + 1] != '0') {
            temp = Sum(p + 1);
            if(Bigger(ans, temp)) ans = temp;
            cnt ++;
        }
        p ++;
    }

    for(int i = 0; i < ans.length();i ++) {
        printf("%c", ans[i]);
    }


    return 0;
}
View Code

 

 

昨天差 1.. TLE 的 B 真是讨厌

C 刚刚读错题意 打扰了 明天再看

还是要给自己找借口昨天开赛之后才发现 咦 有一场比赛 时间不够 但是居然没有掉分 

可爱博主 在线吸桃

唉 写不出题真的很费桃桃 ´・ᴗ・`

 

posted @ 2019-06-17 22:02  丧心病狂工科女  阅读(242)  评论(0编辑  收藏  举报