CodeForces 289A Polo the Penguin and Segments (水题)

题意:给你 n 段区间,而且还是不相交的,然后你只能向左扩展左端点,或者向右扩展右端点,然后扩展最少的步数让整数总数能够整除 k。

析:很简单么,只要在记录算一下数量,然后再算出 k 的倍数差多少就行。

代码如下:

#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
const int maxn = 500 + 5;
const int INF = 0x3f3f3f3f;
const int dr[] = {0, 0, 1, -1};
const int dc[] = {1, -1, 0, 0};

int main(){
    int k, n;
    cin >> n >> k;
    LL sum = 0;
    int l, r;
    for(int i = 0; i < n; ++i){
        scanf("%d %d", &l, &r);
        sum += r - l + 1;
    }
    cout << (k - (sum % k)) % k << endl;
    return 0;
}
原文地址:https://www.cnblogs.com/dwtfukgv/p/5705347.html