ABC201题解
因为学校的某些操作。
让最近两天的\(Atcoder\)都能打了,挺开心的。
想上次\(ABC\)看错题意,失败退场。
——————————————————————————————
\(A\)
直接手动判断六种排列。
A
#include<iostream>
#include<cstdio>
#define ll long long
ll a,b,c;
int main(){
scanf("%lld%lld%lld",&a,&b,&c);
//abc acb bac bca cab cba
if((b - a) == (c - b) || (c - a) == (b - c) || (a - b) == (c - a) || (c - b) == (a - c) || (a - c) == (b - a) || (b - c) == (a - b))
puts("Yes");
else
puts("No");
}
\(B\)
B
#include<iostream>
#include<cstdio>
#include<algorithm>
#define ll long long
#define M 20
#define N 10000
struct P{
char a[M];
int key;
}e[N];
bool operator < (P a,P b){
return a.key > b.key;
}
ll n;
int main(){
scanf("%lld",&n);
for(int i = 1;i <= n;++i)
scanf("%s%d",e[i].a + 1,&e[i].key);
std::sort(e + 1,e + n + 1);
std::cout<<e[2].a + 1<<std::endl;
}
\(C\)
考虑到只有四位数,所以直接枚举并判断是否合法就行。
C
#include<iostream>
#include<cstdio>
#define ll long long
char ai[20];
ll ans;
inline bool check(ll now){
ll a = now / 1000,b = now % 1000 / 100,c = now % 100 / 10,d = now % 10;
for(int i = 0;i <= 9;++i)
if(ai[i] == 'o' && a != i && b != i && c != i && d != i)
return false;
else
if(ai[i] == 'x' && (a == i || b == i || c == i || d == i))
return false;
return true;
}
int main(){
scanf("%s",ai);
for(int i = 0;i <= 9999;++i){
if(check(i))
ans ++ ;
}
std::cout<<ans<<std::endl;
}
\(D\)
没想到\(ABC\)还考\(min-max\)对抗搜索,考虑记录的答案是第一手比第二手高多少分就行了。(据说正解是反着\(dp\))
D
#include<iostream>
#include<cstdio>
#define ll long long
#define N 2005
ll h,w;
ll p[2005][2005],f[N][N];
bool v[N][N];
ll x,y;
inline ll dfs(int turn){
if(v[x][y])return f[x][y];
ll ans = turn ? -0x7f7f7f7f : 0x7f7f7f7f;
if(x + 1 <= h){
x += 1;
if(turn)
ans = std::max(ans,dfs(0) + p[x][y]);
else
ans = std::min(ans,dfs(1) - p[x][y]);
x -= 1;
}
if(y + 1 <= w){
y += 1;
if(turn)
ans = std::max(ans,dfs(0) + p[x][y]);
else
ans = std::min(ans,dfs(1) - p[x][y]);
y -= 1;
}
// std::cout<<turn<<" "<<x<<" "<<y<<" "<<ans<<std::endl;
v[x][y] = 1;
return f[x][y] = ans;
}
int main(){
scanf("%lld%lld",&h,&w);
for(int i = 1;i <= h;++i)
for(int j = 1;j <= w;++j){
char a;
while(a != '+' && a != '-')
a = getchar();
if(a == '+')
p[i][j] = 1;
else
p[i][j] = -1;
a = 'q';
}
x = 1,y = 1;
v[h][w] = 1,f[h][w] = 0;
ll k = dfs(1);
// std::cout<<k<<std::endl;
if(k > 0)
puts("Takahashi");
if(k == 0)
puts("Draw");
if(k < 0)
puts("Aoki");
}
\(E\)
考虑这种树上数对统计答案问题,是可以换根做的。考虑在某个点(\(x\))为根时,求出答案为\(\sum_i dis(x,i)\)就行了。
对于换根操作,考虑到要换到的点到根的异或距离为\(k\),则他到每个点的距离都要异或\(k\),
考虑分位,单位算贡献就好了。
E
#include<iostream>
#include<cstdio>
#define ll long long
#define N 200005
#define mod 1000000007
ll head[N],cnt;
ll n,dis[N],c[N],a[N];
struct P{int to,next;ll wi;}e[N * 2];
inline void add(int x,int y,ll w){
e[++cnt].to = y;
e[cnt].next = head[x];
e[cnt].wi = w;
head[x] = cnt;
}
inline void dfs1(int u,int f){
for(int i = head[u];i;i = e[i].next){
int v = e[i].to;
if(v == f)
continue;
dis[v] = dis[u] ^ e[i].wi;
dfs1(v,u);
}
}
ll ans = 0;
inline void dfs2(int u,int f){
ll k;
for(int i = 0;i < 60;++i){
if(dis[u] & (1ll << i))k = n - c[i];
else
k = c[i];
ans += (1ll << i) % mod * k % mod;
ans %= mod;
}
for(int i = head[u];i;i = e[i].next){
int v = e[i].to;
if(v == f)
continue;
dfs2(v,u);
}
}
int main(){
scanf("%lld",&n);
for(int i = 1;i <= n - 1;++i){
ll u,v,w;
scanf("%lld%lld%lld",&u,&v,&w);
add(u,v,w);
add(v,u,w);
}
dfs1(1,0);
for(int i = 1;i <= n;++i)
for(int j = 0;j < 60;++j)
if(dis[i] & (1ll << j))c[j] ++ ;
dfs2(1,0);
std::cout<<ans * (500000004) % mod<<std::endl;
}
ABC201题解的更多相关文章
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解
题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...
- 2016ACM青岛区域赛题解
A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- poj1399 hoj1037 Direct Visibility 题解 (宽搜)
http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...
- 网络流n题 题解
学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或 ...
- CF100965C题解..
求方程 \[ \begin{array}\\ \sum_{i=1}^n x_i & \equiv & a_1 \pmod{p} \\ \sum_{i=1}^n x_i^2 & ...
随机推荐
- Postman实现SHA256withRSA签名
@ 目录 获取pmlib 引入依赖bundle.js,有以下两种方式: 使用Pre-request Script对请求进行加签(具体加签字段请看自己项目) 获取pmlib 引入依赖bundle.js, ...
- Pycharm无法打开,双击没反应
以下方案皆为引用,仅供参考. 方案一: 1.先声明一下,这种解决方法适用于任何版本的永久破解启动不了的情况(包括:2019版本的)2.下面直接切入正题之所以我们破解之后,不能正常启动的原因有两种:① ...
- FastAPI 学习之路(四十二)定制返回Response
我们想要在接口中返回xml格式的内容,我们应该如何实现呢. from fastapi import FastAPI,Response @app.get("/legacy/") de ...
- ThreadLocalRandom类原理分析
1.Random类及其局限性 public int nextInt(int bound) { if (bound <= 0) throw new IllegalArgumentException ...
- Prometheus的单机部署
Prometheus的单机部署 一.什么是Prometheus 二.Prometheus的特性 三.支持的指标类型 1.Counter 计数器 2.Gauge 仪表盘 3.Histogram 直方图 ...
- 电脑cmd命令快速查看连接过的WIFI密码信息
只是突然发现,好奇心作怪,试了一下,妈妈再也不用担心我忘记家里的wifi密码了 1.直接打开"运行"(win键+R) 2.输入CMD 确定 3.输入下面cmd命令.鼠标粘贴 for ...
- CSP-S 2021 退役记
写的比较草率,但的确是真实感受. 10.23 回寝室前敲了一个 dinic 板子,觉得不会考... 10.24 8:00 起床,还好今天宿管不在,可以起的晚一点. 吃了早饭来机房颓废. 10:00 似 ...
- Bzoj通过5题纪念
我A了五题啦!!!
- 第01课 OpenGL窗口(3)
接下来的代码段创建我们的OpenGL窗口.我花了很多时间来做决定是否创建固定的全屏模式这样不需要许多额外的代码,还是创建一个容易定制的友好的窗口但需要更多的代码.当然最后我选择了后者.我经常在EMai ...
- When overwhelmed, take a break
When overwhelmed by, frustrated with, or tired of the work, taking a break will help with thinking a ...