Educational Codeforces Round 48

Educational Codeforces Round 48


C.Vasya And The Mushrooms

思路很简单,走法有一个统一形式就是先上下走,然后到某个位置左右一个来回。然后就推一下,后边那段的递推式子,枚举改变走法的位置即可。看出做法之后发现要推个式子,于是跑去写D了。。。然后D一开始思路错了。。。凉啊

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define PII pair<int,int>
#define MP make_pair
#define fr first
#define sc second
#define mem(WM) memset(WM,0,sizeof(WM))
typedef long long ll;
typedef unsigned long long ull;
const int N = 3e5 + 7;
using namespace std;
int n;
ll a[N][2],b[N][2],sum[N][2],s[N],A[N][2],num[N][2];
int main() {
    scanf("%d",&n);
    rep(i,1,n)scanf("%I64d",&a[i][0]);
    rep(i,1,n)scanf("%I64d",&a[i][1]);
    rep(i,1,n) s[i] = s[i-1] + a[i][0]+a[i][1];
    sum[n][0] = a[n][1];
    sum[n][1] = a[n][0];
    per(i,n-1,1) {
        sum[i][0] = (s[n]-s[i]) + sum[i+1][0] + ((n-i+1)*2-1)*a[i][1];
        sum[i][1] = (s[n]-s[i]) + sum[i+1][1] + ((n-i+1)*2-1)*a[i][0];
    }
    ll ans = sum[1][0];
    int sy=0,cc=0;
    rep(i,1,n) {
        A[i][sy] = A[i-1][sy] + cc*a[i][sy];
        num[i][sy] = cc;
        sy^=1;++cc;
        ans = max(ans,A[i][sy]);
        A[i][sy] = A[i][sy^1] + cc*a[i][sy];
        num[i][sy] = cc;
        ans = max(ans,A[i][sy]);
        ++cc;
    }
    sy = 1;
    rep(i,1,n) {
        ll tmp = A[i][sy] + sum[i+1][sy] + (s[n] - s[i])*(num[i][sy]+1);
        ans = max(ans,tmp);
        sy^=1;
    }
    printf("%I64d\n",ans);
    return 0;
}

D.Vasya And The Matrix

给定横纵的异或值,让你求一个符合条件的矩阵。拆位之后,通过一行一列控制异或值,再检查以下最后一列/行是否满足条件即可。

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define PII pair<int,int>
#define MP make_pair
#define fr first
#define sc second
#define mem(WM) memset(WM,0,sizeof(WM))
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e5 + 7;
const ll mod = 1e9 + 7;
using namespace std;

int n, m;
ll mp[111][111],a[111],b[111],r[111],c[111];
ll ans[111][111];
int solve() {
    rep(i,1,m-1) {
        if(c[i]==0) rep(j,1,n) mp[j][i]=c[i];
        else {
            mp[1][i] = 1;
            rep(j,2,n) mp[j][i]=0;
        }
    }
    rep(i,1,n) {ll x=0;
        rep(j,1,m-1) x^=mp[i][j];
        if(x==r[i]) mp[i][m] = 0;
        else mp[i][m] = 1;
    }
    ll x=0;
    rep(i,1,n)x^=mp[i][m];
    if(x==c[m]) return 1;

    rep(i,1,n-1) {
        if(!r[i]) rep(j,1,m) mp[i][j]=r[i];
        else {
            mp[i][1] = 1;
            rep(j,2,m) mp[i][j] = 0;
        }
    }
    rep(i,1,m){ll x=0;
        rep(j,1,n-1)x^=mp[j][i];
        if(x==c[i]) mp[n][i] = 0;
        else mp[n][i] = 1;
    }
    x=0;
    rep(i,1,m)x^=mp[n][i];
    if(x==r[n]) return 1;

    return -1;
}
int tmp[111];
int main() {
    scanf("%d%d",&n,&m);
    rep(i,1,n) scanf("%I64d",&a[i]);
    rep(i,1,m) scanf("%I64d",&b[i]);
    rep(x,0,30) {
        rep(i,1,n) r[i] = !!(a[i]&(1<<x));
        rep(i,1,m) c[i] = !!(b[i]&(1<<x));
        int t = solve();
        if(t == -1)
            return puts("NO"),0;
        rep(i,1,n)rep(j,1,m)
            ans[i][j] += (mp[i][j]<<x);
    }
    puts("YES");
    rep(i,1,n) {
        rep(j,1,m) printf("%I64d ",ans[i][j]);puts("");
    }
    return 0;
}

E. Rest In The Shades

大概做法懂了,对每个询问的点它和下方的那个光源的轨迹会形成一个三角形,二分求x轴上两条边中间的覆盖区域即可。这个可以预处理前缀和。二分两个边界,两边要特判一下相交。然后相似三角形即可求出在轨迹上的投影。。。

原文地址:https://www.cnblogs.com/RRRR-wys/p/9417149.html

时间: 2024-10-03 10:57:30

Educational Codeforces Round 48的相关文章

Educational Codeforces Round 48 (Rated for Div. 2)

http://codeforces.com/contest/1016 A. 没想到这个也会TLE,太粗心了 B. 暴力就好了,多情况讨论又出错... 思路跟我一样的解法   为什么我做了那么多讨论,原因是没注意这个: 标记 最后一个字符,同时注意 l+m-3. 特殊情况就 vis 0000011111111111112 s1  abaccabaacabacabacca      红色的地方是 l 和 r ,为了防止在 l 处计数多了就得 l + m - 3 s2  abacca we[s+m-1

Educational Codeforces Round 48 (Rated for Div. 2) - 赛后补题

C. Vasya And The Mushrooms 题解:拿笔画他的行走路线,你会发现可以前缀和预处理一些东西出来. const int N = 300005; int n; ll a[N], b[N], dp[2][N], sp[2][N], sum[N]; int get_a() { dp[0][0] = 0; for (int i = 1; i < n; ++i) { dp[0][i] = dp[0][i - 1] + 1ll * i * a[i]; } int t = n; dp[1]

D. Vasya And The Matrix(Educational Codeforces Round 48)

D. Vasya And The Matrix time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Now Vasya is taking an exam in mathematics. In order to get a good mark, Vasya needs to guess the matrix that the teache

Educational Codeforces Round 48 (Rated for Div. 2) B Segment Occurrences

翻译 给你一个字符串\(s\)和另一个字符串\(t\),然后给你\(q\)个区间,问\(s\)在这些区间里的子串有多少个与\(t\)相同. 思路 一道要细心的模拟题,使用\(STL string\),暴力,前缀和,\(Hash\),\(Kmp\)都能做出来,然后我来介绍一下用 \(vector\)的做法. 首先预处理\(s\),从头到位找到每一个长度是字符串t的长度\(m\)的字符串,如果其与\(t\)相等,那么就往vector中压入\(1\),否则压入\(0\),这样,我们就找到每个编号的字符

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,y为c,\(a_j\)为d;a>=b,c>=d. 假设a>b,c>d,那么由于\(gcd(v,a_i)=x\),v中p的次数为b,由于\(lcm(v,a_j)=y\),那么\(max(b,d)==c\),又c>d,所以b=c<a和x|y矛盾,所以此时ij不满足条件 其他情况

Educational Codeforces Round 21 G. Anthem of Berland(dp+kmp)

题目链接:Educational Codeforces Round 21 G. Anthem of Berland 题意: 给你两个字符串,第一个字符串包含问号,问号可以变成任意字符串. 问你第一个字符串最多包含多少个第二个字符串. 题解: 考虑dp[i][j],表示当前考虑到第一个串的第i位,已经匹配到第二个字符串的第j位. 这样的话复杂度为26*n*m*O(fail). fail可以用kmp进行预处理,将26个字母全部处理出来,这样复杂度就变成了26*n*m. 状态转移看代码(就是一个kmp

Educational Codeforces Round 23 F. MEX Queries(线段树)

题目链接:Educational Codeforces Round 23 F. MEX Queries 题意: 一共有n个操作. 1.  将[l,r]区间的数标记为1. 2.  将[l,r]区间的数标记为0. 3.  将[l,r]区间取反. 对每个操作,输出标记为0的最小正整数. 题解: hash后,用线段树xjb标记一下就行了. 1 #include<bits/stdc++.h> 2 #define ls l,m,rt<<1 3 #define rs m+1,r,rt<&l

Educational Codeforces Round 21 F. Card Game(网络流之最大点权独立集)

题目链接:Educational Codeforces Round 21 F. Card Game 题意: 有n个卡片,每个卡片有三个值:p,c,l; 现在让你找一个最小的L,使得满足选出来的卡片l<=L,并且所有卡片的p的和不小于k. 选择卡片时有限制,任意两张卡片的c之和不能为质数. 题解: 和hdu 1565 方格取数(2)一样,都是求最大点权独立集. 不难看出来,这题再多一个二分. 注意的是在构造二部图的时候,按照c值的奇偶性构造. 当c==1时要单独处理,因为如果有多个c==1的卡片,

Educational Codeforces Round 36 (Rated for Div. 2)

Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x,?y) as the differ