Codeforces Round #567 div2

A
分类讨论分类太乱,漏了给了钱还是买不了的情况。

WA

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    long long x, y, z;
    cin >> x >> y >> z;
    if((x+y)/z == 0)
        cout << 0 << " " << 0 << endl;
    else
    {
        if(x > z && y > z)
        {
            if(abs(x-y) > z)
                cout << (x+y) / z << " "<< min(x%z, y%z) << endl;
            else
            {
                if((x+y)%z == 0)
                    cout << (x+y) / z << " " << (abs(x-y)%z) << endl;
                else
                    cout << (x+y) / z << " " << (abs(x-y)%z)/2 << endl;
            }
        }


        else
            cout << (x+y) / z << " " << min(abs(z-y), abs(z-x)) << endl;

    }

    return 0;
}

WA

#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
    long long x, y, z, ans;
    cin >> x >> y >> z;
    cout << (x+y) / z << " ";

    if(x < z && y < z)
        ans = min(z-x, z-y);
    else
    {
        if((x+y)%z == 0)
            ans = min(abs(z-y)%z, abs(z-x)%z);
        else
            ans = min((x+y - (x+y)%z)-x,(x+y - (x+y)%z)-y);
    }

    cout << ans << endl;
    return 0;
}

B
10e5是string串的长度,而不是数据规模,所以肯定超过了ll。大数。

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

//(2≤l≤100000
int l, ans = 9999999, dp[100010];
string num;

int split(int a)
{
    //cout << "   **  fun split  **   " << endl;
    int left = 0, right = 0, sum = 0, cnt = 1;

    for(int i = a-1;i >= 0;i--)
    {
        if(a-1 < 0)
            continue;
        else
        {
            left += (num[i] - '0')*cnt;
            cnt *= 10;
        }
        //cout << "num[" << i << "] = " << num[i] << " left = " <<left << endl;
    }

    cnt = 1;
    for(int i = l-1;i >= a;i--)
    {
        right += (num[i] - '0')*cnt;
        cnt *= 10;
        //cout << "num[" << i << "] = " << num[i] << " right = " <<right << endl;
    }

    sum = left + right;

    //cout << "left = " << left << "right = " << right << "sum = " <<sum <<endl;
    return sum;
}

int main()
{
    cin >> l >> num;
    //dp[0] = 999999;//dp[i] = j 从第i个位置的数字之前切割和的最大值


    if(l % 2 == 0)
    {
        int mid = l / 2;
        for(int i = 0;i < l/2;i++)
        {
            if(num[mid + i] == '0')
                continue;
            else
                ans = min(split(mid + i), ans);

            if(num[mid + i] == '0')
                continue;
            else
                ans = min(split(mid - i), ans);
        }
        ans = min(ans, split(0));
    }
    else
    {
        if(num[l/2] != '0')
            ans = split(l/2);

        int mid = l/2;
        for(int i = 0;i <= l/2;i++)
        {
            if(num[mid+i] == '0')
                continue;
            else
                ans = min(ans, split(mid + i));

            if(num[mid-i] == '0')
                continue;
            else
                ans = min(ans, split(mid - i));
        }
    }

    cout << ans << endl;

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值