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 & ...
随机推荐
- css如何简单设置文字溢出盒子显示省略号
1.单行文本溢出显示省略号单行文本溢出显示省略号,必须满足三个条件:(1)先强制一行内显示文本white-space:nowrap;(默认 normal自动换行)(2)超出的部分隐藏overflow: ...
- 保护模式篇——TLB与CPU缓存
写在前面 此系列是本人一个字一个字码出来的,包括示例和实验截图.由于系统内核的复杂性,故可能有错误或者不全面的地方,如有错误,欢迎批评指正,本教程将会长期更新. 如有好的建议,欢迎反馈.码字不易, ...
- Takin Talks·上海 |开源后首场主题研讨会来了,一起解密Takin技术吧!
自 6 月 25 日全球首款生产环境全链路压测平台 Takin 正式开源,短短 13 天时间,Github 主页上 Star 数已超过 730,开发者社群也积累了 1500+粉丝.群内技术研讨氛围 ...
- Sobol 序列并行化的实践经验
目录 Sobol 序列并行化的实践经验 随机数发生器并行化的常见策略 Sobol 序列的原理和跳转功能 Sobol 序列并行化实践 分块策略 蛙跳策略 蛙跳策略的计算量分析 减少异或计算的技巧 分块策 ...
- [no code][scrum meeting] Alpha 15
项目 内容 会议时间 2020-04-23 会议主题 OCR紧急会议 会议时长 45min 参会人员 PM + OCR组(赵涛,黎正宇) 项目 内容 会议时间 2020-04-24 会议主题 全体测试 ...
- Spring动态添加定时任务
Spring动态添加定时任务 一.背景 二.需求和实现思路 1.能够动态的添加一个定时任务. 2.能够取消定时任务的执行. 3.动态的修改任务执行的时间. 4.获取定时任务执行的异常 三.代码实现 四 ...
- 算法:九宫格问题--奇数阶魔方(Magic-Square)
一.魔方介绍 魔方(这里是简称,也可以叫幻方.魔术矩阵,Magic Square)是 n×n 正方形网格(n 为每侧的单元数),里面每个单元格填充了不同的正整数 1, 2, 3, ... , n2,并 ...
- Huffman算法
一.Huffman算法介绍 霍夫曼编码(英语:Huffman Coding),又译为哈夫曼编码.赫夫曼编码,是一种用于无损数据压缩的熵编码(权编码)算法.在计算机数据处理中,霍夫曼编码使用变长编码表对 ...
- JVM:Java内存区域与内存溢出异常
Java 虚拟机在执行 Java 程序的过程中会把它所管理的内存划分为若干个不同的数据区域.这些区域都有各自的用途,以及创建和销毁时间,有些区域随着虚拟机进程的启动而存在,有些区域依赖用户线程的启动和 ...
- usb设备无法识别
之前用飞线用旧板子飞线连接了一个wifi模块到usb0口上,调试ok的,现在新设计的板子回来了,wifi模块是连接在usb2口上的,系统起来后发现wlan0不存在,用lsusb查看wifi模块的usb ...