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 + ;
int n;
ll a[][N], sum123[][N], sum321[][N], sum[][N];
int main() {
ios::sync_with_stdio(false);
cin.tie();
cin >> n;
for(int i = ; i < ; i++) {
for(int j = ; j <= n; j++) {
cin >> a[i][j];
}
}
for(int i = ; i < ; i++) {
for(int j = n; j >= ; j--) {
sum[i][j] = sum[i][j + ] + a[i][j];
sum123[i][j] = sum123[i][j + ] + (ll)(j - ) * a[i][j];
sum321[i][j] = sum321[i][j + ] + (ll)(n + n - j) * a[i][j];
}
}
ll S = , ans = , Sum = , now = ;
ll cnt = , cur = ;
for(ll j = ; j <= n; j++) {
Sum += sum123[cur][j + ] + (j - ) * sum[cur][j + ];
Sum += sum321[cur ^ ][j] + (j - ) * sum[cur ^ ][j];
ans = max(ans, Sum);
now += a[cur ^ ][j] * cnt; cnt++;
now += a[cur ^ ][j + ] * cnt; cnt++;
Sum = now;
cur ^= ;
}
cout << ans;
return ;
}

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 = ;
ll a[N], b[N];
int n, m;
int main() {
ios::sync_with_stdio(false);
cin.tie();
cin >> n >> m;
ll cur = ;
for(int i = ; i <= n; i++)
cin >> a[i], cur ^= a[i];
for(int i = ; i <= m; i++)
cin >> b[i], cur ^= b[i];
if(cur != ) {
cout << "NO";
return ;
}
cout << "YES" << '\n';
cur = a[];
for(int i = ; i <= m; i++)
cur ^= b[i];
cout << cur;
for(int i = ; i <= m; i++)
cout << ' ' << b[i];
cout << '\n';
for(int i = ; i <= n; i++) {
for(int j = ; j <= m; j++) {
if(j == )
cout << a[i];
else
cout << ' ' << ;
}
cout << '\n';
}
return ;
}

Educational Codeforces Round 48 (Rated for Div. 2) CD题解的更多相关文章

  1. Educational Codeforces Round 59 (Rated for Div. 2) DE题解

    Educational Codeforces Round 59 (Rated for Div. 2) D. Compression 题目链接:https://codeforces.com/contes ...

  2. Educational Codeforces Round 48 (Rated for Div. 2)

    http://codeforces.com/contest/1016 A. 没想到这个也会TLE,太粗心了 B. 暴力就好了,多情况讨论又出错... 思路跟我一样的解法   为什么我做了那么多讨论,原 ...

  3. Educational Codeforces Round 48 (Rated for Div. 2) B 1016B Segment Occurrences (前缀和)

    B. Segment Occurrences time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  4. Educational Codeforces Round 48 (Rated for Div. 2)异或思维

    题:https://codeforces.com/contest/1016/problem/D 题意:有一个 n * m 的矩阵, 现在给你 n 个数, 第 i 个数 a[ i ] 代表 i 这一行所 ...

  5. Educational Codeforces Round 48 (Rated for Div. 2)——A. Death Note ##

    A. Death Note time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  6. Educational Codeforces Round 48 (Rated for Div. 2)G. Appropriate Team

    题意:求满足条件的(i,j)对数:\(gcd(v,a_i)=x,lcm(v,a_j)=y\) 题解:\(x|a_i,a_j|y\),\(x|y\),考虑质因子p,假设a_i中p次数为a,x中次数为b, ...

  7. Educational Codeforces Round 48 (Rated for Div. 2) D 1016D Vasya And The Matrix (构造)

    D. Vasya And The Matrix time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  8. 【Educational Codeforces Round 48 (Rated for Div. 2) C】 Vasya And The Mushrooms

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然在没有一直往右走然后走到头再往上走一格再往左走到头之前. 肯定是一直在蛇形走位.. 这个蛇形走位的答案贡献可以预处理出来.很容易 ...

  9. 【Educational Codeforces Round 48 (Rated for Div. 2) D】Vasya And The Matrix

    [链接] 我是链接,点我呀:) [题意] 告诉你每一行.每一列的异或和. 让你求出一个符合要求的原矩阵. [题解] 显然应该有 a1^a2^....^an = b1^b2^....^bn 也即两边同时 ...

随机推荐

  1. PHP计算两个已知经纬度之间的距离

    /** *求两个已知经纬度之间的距离,单位为千米 *@param lng1,lng2 经度 *@param lat1,lat2 纬度 *@return float 距离,单位千米 **/ privat ...

  2. Ubuntu16.04安装wps办公软件解决文字缺失

    先到wps官网下载linux版wps安装包 选择64位的alpha版本下载: 下载完后,同样是cd到Downloads目录,用dpkg命令来安装它: cd  Downloads/ sudo dpkg ...

  3. Hadoop第一课:Hadoop集群环境搭建

    一. 检查列表 1.1.网络访问 设置电脑IP以及可以访问网络设置:进入etc/sysconfig/network-scripts/,使用命令“ls -all” 查看文件.会看到ifcfg-lo文件然 ...

  4. Python3 Tkinter-Spinbox

    1.创建 from tkinter import * root=Tk() Spinbox(root).pack() root.mainloop() 2.参数 from_    最小值 to    最大 ...

  5. java.net.ProtocolException: Server redirected too many times

    网页爬虫时,原来正常的代码,可能是因为网站做了cookie校验处理,报异常:java.net.ProtocolException: Server redirected too many times 表 ...

  6. VUE中组件的使用

    关于vue组件引用 使用Nodejs的方法 被引用的组件要暴露 module.exports={}; 引用时 用 var abc= require("组件的路径") 然后 就可以用 ...

  7. Java 集合框架之Collection

    此图是 java 中 Collection 相关的接口与类的关系的类图.其中,类只是集合框架的一部分,比较常用的一部分. 第一次画类图,着实很费劲,不过收获也不小. 下面是相关接口和类的解释说明.文字 ...

  8. 使用cout进行格式化

    以下内容摘自木缥缈的博客 使用cout进行格式化 ostream插入运算符将值转换为文本格式.在默认情况下,格式化值的方式如下. * 对于char值,如果它代表的是可打印字符,则将被作为一个字符显示在 ...

  9. ACM hust 2.1

    来自咸鱼王的呻吟 http://www.xiami.com/song/3599639?spm=a1z1s.3521865.23309997.1.PbLu7E 配合咸鱼食用效果更佳(右键新窗口打开) 题 ...

  10. python urllib使用

    Urllib是python内置的HTTP请求库包括以下模块urllib.request 请求模块urllib.error 异常处理模块urllib.parse url解析模块urllib.robotp ...