Educational Codeforces Round 48 (Rated for Div. 2) CD题解

Educational Codeforces Round 48 (Rated for Div. 2)

C. Vasya And The Mushrooms

题目链接:https://codeforces.com/contest/1016/problem/C

题意:

emmm,说不清楚,还是直接看题目吧。

 

题解:

这个题人行走的方式是有一定的规律的,最后都是直接走到底,然后从另外一行走回来。并且通过画图观察,会发现他走到格子的时间会有一定的规律。

所以就维护几个前缀和就行了,从1到n枚举一下,还要维护一下目前走过的格子对答案的贡献,如果是奇数那么当前就是从上面出发,如果是偶数就是从下面出发,计算答案的时候根据规律来就行了。

代码如下:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 5 ;
int n;
ll a[2][N], sum123[2][N], sum321[2][N], sum[2][N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 0; i < 2; i++) {
        for(int j = 1; j <= n; j++) {
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < 2; i++) {
        for(int j = n; j >= 1; j--) {
            sum[i][j] = sum[i][j + 1] + a[i][j];
            sum123[i][j] = sum123[i][j + 1] + (ll)(j - 1) * a[i][j];
            sum321[i][j] = sum321[i][j + 1] + (ll)(n + n - j) * a[i][j];
        }
    }
    ll S = 0, ans = 0, Sum = 0, now = 0;
    ll cnt = 1, cur = 0;
    for(ll j = 1; j <= n; j++) {
        Sum += sum123[cur][j + 1] + (j - 1) * sum[cur][j + 1];
        Sum += sum321[cur ^ 1][j] + (j - 1) * sum[cur ^ 1][j];
        ans = max(ans, Sum);
        now += a[cur ^ 1][j] * cnt; cnt++;
        now += a[cur ^ 1][j + 1] * cnt; cnt++;
        Sum = now;
        cur ^= 1;
    }
    cout << ans;
    return 0;
}
View Code

 

D. Vasya And The Matrix

题目链接:https://codeforces.com/contest/1016/problem/D

题意:

给出每一行和每一列的异或值,要求你构造一个矩阵满足这个异或值。

 

题解:

这个构造还是挺巧妙的,首先先把a2...an和b2,b3...bm安排好,然后对于(1,1)这个位置,构造a1^b2^b3...^bm,其余全是0就行了,这个还是比较容易证明的。

反正就是很巧妙。。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 105;
ll a[N], b[N];
int n, m;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    ll cur = 0;
    for(int i = 1; i <= n; i++)
        cin >> a[i], cur ^= a[i];
    for(int i = 1; i <= m; i++)
        cin >> b[i], cur ^= b[i];
    if(cur != 0) {
        cout << "NO";
        return 0;
    }
    cout << "YES" << '\n';
    cur = a[1];
    for(int i = 2; i <= m; i++)
        cur ^= b[i];
    cout << cur;
    for(int i = 2; i <= m; i++)
        cout << ' ' << b[i];
    cout << '\n';
    for(int i = 2; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            if(j == 1)
                cout << a[i];
            else
                cout << ' ' << 0;
        }
        cout << '\n';
    }
    return 0;
}
View Code

 

posted @ 2019-03-17 22:25  heyuhhh  阅读(136)  评论(0编辑  收藏  举报