Codeforces Round #353 (Div. 2) Editorial

**

675A - Infinite Sequence

**
题意:给三个数a,b,c(- 1e9 ≤ a, b, c ≤ 1e9)
a是一个数组的第一个数,c是这个数组的公差,问你能不能这个数组中找到b
解法:分情况讨论,当a=b时,c随便都行
当a!=b时,只需要判断|b - a| % |c| == 0 && (b - a) * c > 0即可

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define eps 1e-6
typedef long long LL;
const double pi = acos(-1.0);
const long long mod = 1e9 + 7;
using namespace std;

int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    int ok = 0;
    if(b > a && c > 0)
    {
        if( (b - a) % c == 0)
            ok = 1;
    }
    else if(b == a)
        ok = 1;
    else if(b < a && c < 0)
    {
        c = -c;
        if( (a - b) % c == 0)
            ok = 1;
    }
    if(ok)
        puts("YES");
    else
        puts("NO");
    return 0;
}
#include <bits/stdc++.h>

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    if (c == 0) {
        if (a == b) cout << "YESn";
        else cout << "NOn";
    } else {
        if ((b - a) % c == 0 && (b - a) / c >= 0) cout << "YESn";
        else cout << "NOn";
    }
}

**

675B - Restoring Painting

**
题意:一个9宫格,给出4个位置上的数字,5个位置上是不确定的,现在问你有多少种放置方法可以让左上,左下,右上,右下的四个2*2的格子的和相等
解法:中间的格子不管放几都不会影响答案,于是随意放,有N种放法。下面讨论左上,左下,右上,右下的这4个格子的放法,由a,b,c,d四个数字的关系,可以得到这4个格子的关系,详细看代码

#include <iostream>

using namespace std;

int main() {
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;

    long long ans = 0;
    for (int x = 1; x <= n; x++) {
        int y = x + b - c;
        int z = x + a - d;
        int w = a + y - d;
        if (1 <= y && y <= n && 1 <= z && z <= n && 1 <= w && w <= n) {
            ans++;
        }
    }
    ans *= n;

    cout << ans << endl;
}
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define eps 1e-6
typedef long long LL;
const double pi = acos(-1.0);
const long long mod = 1e9 + 7;
using namespace std;
LL s[4];
int main()
{
    int a,b,c,d,n;
    scanf("%d %d %d %d %d",&n,&a,&b,&c,&d);
    s[0] = a + b;s[1] = a + c;
    s[2] = c + d;s[3] = b + d;
    sort(s,s + 4);
    LL ans = (n - s[3] + s[0]) * n;
    if(ans < 0)
        ans = 0;
    printf("%I64d\n",ans);
    return 0;
}

**

675C - Money Transfers

**
题意:有一个城市,有n个银行,围成一个圈,n个银行的存款之和为0,只能在相邻的银行之间转账,问最少需要多少次转账才能把所有的银行的存款都变为零

#include <bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n;
    cin >> n;
    map<long long, int> d;
    long long sum = 0;
    int ans = n - 1;
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        sum += t;
        d[sum]++;
        ans = min(ans, n - d[sum]);
    }
    cout << ans << endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值