Codeforces Round #542 div1

A

同一起点如果有多个任务的话 最后走最短的那个 有几个走几次
然后把每个起点的贡献取一个max即可
在“会有跨越起点的情况”那里自闭了好久。。
但实际上每个点如果只走一次的话贡献的最远距离就是起点到它的距离+它要走的距离

#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
#include <vector>
#include <set>
#define sub(x, y) (x >= y ? x - y : x + n - y)
using namespace std;
const int N = 1e5 + 5;
int n, m;
int len[N];
long long cnt[N];
int main(){ 
    scanf("%d%d", &n, &m);
    memset(len, 0x3f, sizeof(len));
    for(int i = 1, x, y; i <= m; ++i){
        scanf("%d%d", &x, &y);
        ++cnt[x]; len[x] = min(len[x], sub(y, x));
    }
    for(int i = 1; i <= n; ++i) if(cnt[i]) cnt[i] = (cnt[i] - 1) * n; else cnt[i] = -1;
    
    for(int i = 1; i <= n; ++i){
        long long ans = 0;
        for(int j = 1; j <= n; ++j) if(~cnt[j])
            ans = max(ans, cnt[j] + len[j] + sub(j, i));
        printf("%lld ", ans);
    }
    return 0;
}

B

怀疑这是假的。。
钦定数组长度为2000 设后面1999项的和为x
那么2000(x - 1) - 1999x = k
解得x = k

#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
#include <vector>
#include <set>
#define sub(x, y) (x >= y ? x - y : x + n - y)
using namespace std;
const int N = 1e6;
int main(){ 
    int k; scanf("%d", &k); k += 2000;
    printf("2000\n-1 ");
    for(int i = 2; i <= 2000; ++i) printf("%d ", k > N ? N : k), k -= (k > N ? N : k);
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/hjmmm/p/10798030.html