传送门


A、B、C、D、F比较简单,没必要写出来


E - Distance on Large Perfect Binary Tree

题目

问一个深度为 \(n\)的满二叉树有多少个点对的距离恰好为 \(D\)

\(n\leq 10^6,D\leq 2*10^6\)


分析

其实此题也比较简单但是赛时没调出来QAQ

考虑分成两种情况讨论,一种情况是其中一个为 \(LCA\),

那么这个就是\(\sum_{i=1}^n2^{i-1}*2^D[i+D\leq n]\)

另一种就枚举其中一个点往下的度数,也就是

\[\frac{1}{2}\sum_{i=1}^n2^{i-1}\sum_{x=1}^{D-1}2^x*2^{D-x}[i+D-x\leq n][i+x\leq n]
\]

也就是

\[\frac{1}{2}\sum_{i=1}^n2^{i-1}\sum_{x=max(1,i+D-n)}^{min(n-i,D-1)}2^D
\]

代码

#include <cstdio>
#define rr register
using namespace std;
const int mod=998244353;
int two[2000011],ans,n,m;
inline signed max(int a,int b){return a>b?a:b;}
inline signed min(int a,int b){return a<b?a:b;}
signed main(){
scanf("%d%d",&n,&m),two[0]=1;
for (rr int i=1;i<=n*2;++i) two[i]=2ll*two[i-1]%mod;
for (rr int i=1;i<=n;++i){
rr int l=max(1,i+m-n),r=min(m-1,n-i);
if (l<=r) ans=(ans+1ll*(r-l+1)*two[i-1]%mod*two[m-1]%mod)%mod;
}
for (rr int i=m+1;i<=n;++i) ans=(ans+two[i])%mod;
return !printf("%d",ans);
}

G - Isosceles Trapezium

题目

给定 \(n\) 个点,点权为 \(w_i\),

问其中四个点构成的等腰梯形的最大点权和


分析

等腰梯形的上底和下底中点的连线垂直于上底和下底,用这个性质枚举线段即可


代码

#include <cstdio>
#include <cctype>
#include <map>
#include <algorithm>
#define rr register
using namespace std;
const int N=1011; typedef long long lll;
map<pair<double,double>,int>uk; lll ans=-4e9;
map<pair<lll,lll>,lll>K[N*N]; int n,lA,lB,cnt;
map<pair<lll,lll>,lll>::iterator it;
struct Point{lll x,y,w;}a[N],A[N*N],B[N*N];
inline signed iut(){
rr int ans=0,f=1; rr char c=getchar();
while (!isdigit(c)) f=(c=='-')?-f:f,c=getchar();
while (isdigit(c)) ans=(ans<<3)+(ans<<1)+(c^48),c=getchar();
return ans*f;
}
inline lll max(lll a,lll b){return a>b?a:b;}
bool cmpx(Point x,Point y){return x.x<y.x||(x.x==y.x&&x.y<y.y);}
bool cmpy(Point x,Point y){return x.y<y.y||(x.y==y.y&&x.x<y.x);}
signed main(){
n=iut();
for (rr int i=1;i<=n;++i)
a[i]=(Point){iut(),iut(),iut()};
for (rr int i=1;i<n;++i)
for (rr int j=i+1;j<=n;++j){
rr Point t=(Point){a[i].x+a[j].x,a[i].y+a[j].y,a[i].w+a[j].w};
if (a[i].x==a[j].x) A[++lA]=t;
else if (a[i].y==a[j].y) B[++lB]=t;
else {
rr double k=(double)(a[j].x-a[i].x)/(a[i].y-a[j].y),b=t.y-k*t.x;
if (!uk[make_pair(k,b)]) uk[make_pair(k,b)]=++cnt;
rr int pos=uk[make_pair(k,b)];
rr lll now=K[pos][make_pair(t.x,t.y)];
K[pos][make_pair(t.x,t.y)]=max(now,t.w);
}
}
for (rr int i=1;i<=cnt;++i){
rr lll now=-2e9;
for (it=K[i].begin();it!=K[i].end();++it){
if (now!=-2e9) ans=max(ans,now+(it->second));
now=max(now,it->second);
}
}
sort(A+1,A+1+lA,cmpy),sort(B+1,B+1+lB,cmpx);
for (rr int l=1,r;l<=lA;l=r+1){
for (r=l;A[l].y==A[r].y;++r); --r;
rr int j=l; rr lll now=-2e9;
for (rr int i=l+1;i<=r;++i){
for (;A[j].x<A[i].x;++j) now=max(now,A[j].w);
if (now!=-2e9) ans=max(ans,now+A[i].w);
}
}
for (rr int l=1,r;l<=lB;l=r+1){
for (r=l;B[l].x==B[r].x;++r); --r;
rr int j=l; rr lll now=-2e9;
for (rr int i=l+1;i<=r;++i){
for (;B[j].y<B[i].y;++j) now=max(now,B[j].w);
if (now!=-2e9) ans=max(ans,now+B[i].w);
}
}
if (ans==-4e9) printf("-1");
else printf("%lld",ans);
return 0;
}

H - Security Camera

题目

给出一张 \(n\) 个点,\(m\) 条边的无向图,问有多少个点集相邻的边数量为偶数

\(n\leq 40\)


分析

这个相邻的边不好搞,不过点集的补集要满足其导出子图的边数与 \(m\) 奇偶性相同。

理应用meet in the middle写的,但是其实可用状态很少,直接dp在2s内还是可以跑过的

设 \(dp[i][x][y]\) 表示前 \(i\) 个点之间连边奇偶性为 \(x=0/1\)

且第 \(i\) 个点之后的连边奇偶性状态为 \(y\) 的点集数量


代码

int main(){
n=iut(),m=iut();
for (rr int i=1;i<=m;++i){
rr int x=iut(),y=iut();
a[x]|=1ll<<(y-x-1);//扔掉小于x的状态
}
dp[0][m&1][0]=1;
for (rr int i=0;i<n;++i)
for (rr int j=0;j<2;++j)
for (it=dp[i][j].begin();it!=dp[i][j].end();++it){
rr lll fi=it->first,se=it->second;
dp[i+1][(j^fi)&1][(fi>>1)^a[i+1]]+=se;//选择这个点就要判断与该点连边的边数是否为奇数
dp[i+1][j][fi>>1]+=se;
}
return !printf("%lld",dp[n][0][0]);
}

AtCoder Beginner Contest 220的更多相关文章

  1. AtCoder Beginner Contest 220部分题(G,H)题解

    刚开始的时候被E题卡住了,不过发现是个数学题后就开始使劲推式子,幸运的是推出来了,之后的F题更是树形DP换根的模板吧,就草草的过了,看了一眼G,随便口胡了一下,赶紧打代码,毕竟时间不多了,最后也没打完 ...

  2. AtCoder Beginner Contest 220 A-F

    A #include <iostream> using namespace std; int main() { int a, b, c; cin >> a >> b ...

  3. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  4. AtCoder Beginner Contest 052

    没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...

  5. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  6. AtCoder Beginner Contest 136

    AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...

  7. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

  8. AtCoder Beginner Contest 076

    A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...

  9. AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】

    AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...

  10. AtCoder Beginner Contest 064 D - Insertion

    AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...

随机推荐

  1. collections模块下的defaultdict用法

    defaultdict from collections import defaultdict s=[('yellow',1),('blue', 2), ('yellow', 3), ('blue', ...

  2. Vue3学习(十九) - TreeSelect 树选择

    写在前面 我知道自己现在的状态很不好,以为放个假能好好放松下心情,结果昨晚做梦还在工作,调试代码,和领导汇报工作. 天呐,明明是在放假,可大脑还在考虑工作的事,我的天那,这是怎么了? Vue页面参数传 ...

  3. 自定义ConditionalOnXX注解(二)

    一.前言 在之前的文章<自定义ConditionalOnXX注解>中,介绍了Conditional注解的实现原理和实现自定义Conditional注解的基础方法,但是有些场景我们需要用一个 ...

  4. 【Openxml】如何为OpenXml元素创建超链接

    已知在OpenXml有以下几种超链接 功能 说明 跳转页面 跳转某一页:ppaction://hlinksldjump跳转第一页:ppaction://hlinkshowjump?jump=first ...

  5. Taurus.MVC WebMVC 入门开发教程7:部分视图和页面片段(结束篇)

    本系列的目录大纲为: Taurus.MVC WebMVC 入门开发教程1:框架下载环境配置与运行 Taurus.MVC WebMVC 入门开发教程2:一个简单的页面呈现 Taurus.MVC WebM ...

  6. IISExpress 跨域cookie的奇怪问题

    测试环境 WIN10,IIS 10,IISExpress 10,Chrome 120,Microsoft Edge 114 网站A 端口7001 只有1个Default.aspx,无前端代码.逻辑很简 ...

  7. Java 属性赋值的先后顺序

    1 package com.bytezero.circle; 2 /** 3 * 4 * @Description 5 * @author Bytezero·zhenglei! Email:42049 ...

  8. ventoy集成微PE+优启通;vmware虚拟机如何进入PE系统,ventoy启动盘制作。

    Ventoy下载地址:Ventoyhttps://www.ventoy.net/cn/index.html 一.Ventoy介绍 Ventoy是一个制作可启动U盘的开源工具.有了Ventoy你就无需反 ...

  9. xxl-job的基本使用

    xxl-job的基本使用 xxl-job是分布式的调度平台调度执行器执行任务,使用的是DB锁(for update)来保证集群分布式调用的一致性,学习简单,操作容易,成本不高. 准备阶段 服务端配置 ...

  10. ansible-vault 教程

    基本使用 在编写playbook时,可能会涉及到一些敏感的数据,比如密码,当这些敏感数据以明文的方式存储在playbook中时,可能是不能被接受的,那么我们该怎么办呢?ansible官方已经考虑到了这 ...