BestCoder Round #61 HDOJ5522 5523 5524题解
来源:互联网 发布:知行论坛北交大 编辑:程序博客网 时间:2024/06/11 19:18
题目链接: 点击打开链接
A: 直接无脑暴力枚举三个数, 或者枚举前两个数, 第三个数二分, 我用了stl的lower_bound()
AC代码:
#include "iostream"#include "cstdio"#include "cstring"#include "algorithm"using namespace std;const int MAXN = 105;int n, a[MAXN];int main(int argc, char const *argv[]){ while(scanf("%d", &n) != EOF) { bool flag = false; for(int i = 1; i <= n; ++i) scanf("%d", &a[i]); sort(a + 1, a + n + 1); for(int i = 1; i <= n - 2; ++i) { for(int j = i + 1; j <= n - 1; ++j) { int x = a[i] + a[j]; int *pos = lower_bound(a + j + 1, a + n + 1, x); if(*pos == x) { flag = true; printf("YES\n"); break; } } if(flag) break; } if(!flag) printf("NO\n"); } return 0;}
B: 分析后对变量分类讨论即可, n为1或起点与终点在两端则ans为0, 起点与终点重合则ans为-1, 起点与终点相邻或起点在两端ans为1,
其他情况ans为2.
AC代码:
#include "iostream"#include "cstdio"#include "cstring"#include "algorithm"using namespace std;const int MAXN = 1e4;int n, s, t;int main(int argc, char const *argv[]){while(scanf("%d", &n) != EOF) {scanf("%d%d", &s, &t);if(n == 1 || (s == 1 && t == n) || (s == n && t == 1)) {printf("0\n");continue;}if(s == t) {printf("-1\n");continue;}if(s - t == 1 || s - t == -1) {printf("1\n");continue;}if(s == 1 || s == n) {printf("1\n");continue;}printf("2\n");}return 0;}
C: 一棵完全二叉树的左右子树都为完全二叉树, 有一棵子树的最后一层是满的, 每一层的节点子树形态相同, 统计后递归求解另一颗子
树即可得到答案.
AC代码:
#include "iostream"#include "cstdio"#include "cstring"#include "algorithm"#include "set"using namespace std;typedef long long ll;ll n;set<ll> s;void dfs(ll x){if(x == 0 || s.count(x) > 0) return;s.insert(x);if((--x & 1) == 0) dfs(x >> 1);else {dfs(x >> 1);dfs((x >> 1) + 1);}}int main(int argc, char const *argv[]){while(scanf("%lld", &n) != EOF) {s.clear();dfs(n);printf("%lu\n", s.size());}return 0;}
1 0
- BestCoder Round #61 HDOJ5522 5523 5524题解
- BestCoder Round #4 题解
- BestCoder Round #18题解
- 【BestCoder Round #22】题解、
- BestCoder Round #22 【题解】
- BestCoder Round #84 题解
- BestCoder Round #85题解
- BestCoder Round #85题解
- BestCoder Round #84题解报告
- BestCoder Round #85题解报告
- BestCoder Round #85 题解(待续)
- BestCoder Round #85 前三题题解
- BestCoder Round #85题解报告
- BestCoder Round #86题解报告
- BestCoder Round #86题解报告
- BestCoder Round #89题解报告
- BestCoder Round #92 题解 (待续)
- BestCoder Round #11 (Div. 2)题解集合
- JS学习笔记(01)—— 基础
- nyoj 中位数 124 (数学)
- centos 安装KVM及使用
- eclipse javaweb 项目异常
- 疯狂JAVA讲义4.1--截取中文字符串
- BestCoder Round #61 HDOJ5522 5523 5524题解
- 菜单 install parallets tools,同时解决 kernel sources 错误
- VC++中文件类型小结
- 读史可以明智
- LightOJ - 1180 Software Company(二分+dp)
- ios中实现staggeringBeauty的效果(二)
- 单例的一种新的写法
- Java数据结构与算法之优先级队列
- 安装系统时出现-安装程序无法创建新的系统分区,也无法定位现有的系统分区,解决方法