[HDOJ]BestCoder Round #61
2015-10-31 22:25
204 查看
[HDOJ5522]Numbers
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5522
数据范围n<=100,暴力枚举即可。担心卡常数做了一下常数的优化。
[HDOJ5523]Game
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5523
可以想到最坏的情况就是起点和终点在非边界的两侧且不相邻,那么这样会把宝石分为三段,这样必须使用两次超能力。如果起点终点相邻,那么只需要使用一次超能力。如果起点终点分别在两端,那么不需要使用超能力。如果起点终点位置一样,那么默认起点是被遍历到了的,再也无法走到起(终)点,此时无解(前提是n>1)。
[HDOJ5524]Subtree
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5524
问一棵完全二叉树有多少种子树包含的节点数量不同。
首先可以肯定的是,一棵完全二叉树有可能是满二叉树,满二叉树的子树依然是满二叉树。但是完全二叉树的子树有一棵是满二叉树,另一棵是完全二叉树。根据给定节点数量很轻易可以知道左右子树的形态,然后递归求解。n的数量太大要用long long。
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5522
数据范围n<=100,暴力枚举即可。担心卡常数做了一下常数的优化。
#include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include <climits> #include <complex> #include <fstream> #include <cassert> #include <cstdio> #include <bitset> #include <vector> #include <deque> #include <queue> #include <stack> #include <ctime> #include <set> #include <map> #include <cmath> using namespace std; const int maxn = 111; int a[maxn]; int n; inline bool scan_d(int &num) { char in;bool IsN=false; in=getchar(); if(in==EOF) return false; while(in!='-'&&(in<'0'||in>'9')) in=getchar(); if(in=='-'){ IsN=true;num=0; } else num=in-'0'; while(in=getchar(),in>='0'&&in<='9') { num*=10,num+=in-'0'; } if(IsN) num=-num; return true; } int main() { while(scan_d(n)) { for(int i = 0; i < n; i++) scan_d(a[i]); sort(a, a+n); int flag = 0; for(int i = 0; i < n; i++) { if(flag) break; for(int j = i; j < n; j++) { if(flag) break; for(int k = 0; k < n; k++) { if(k == i || k == j || i == j) continue; if(a[j] - a[i] == a[k]) { flag = 1; break; } } } } flag ? printf("YES\n") : printf("NO\n");; } }
[HDOJ5523]Game
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5523
可以想到最坏的情况就是起点和终点在非边界的两侧且不相邻,那么这样会把宝石分为三段,这样必须使用两次超能力。如果起点终点相邻,那么只需要使用一次超能力。如果起点终点分别在两端,那么不需要使用超能力。如果起点终点位置一样,那么默认起点是被遍历到了的,再也无法走到起(终)点,此时无解(前提是n>1)。
#include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include <climits> #include <complex> #include <fstream> #include <cassert> #include <cstdio> #include <bitset> #include <vector> #include <deque> #include <queue> #include <stack> #include <ctime> #include <set> #include <map> #include <cmath> using namespace std; inline bool scan_d(int &num) { char in;bool IsN=false; in=getchar(); if(in==EOF) return false; while(in!='-'&&(in<'0'||in>'9')) in=getchar(); if(in=='-'){ IsN=true;num=0; } else num=in-'0'; while(in=getchar(),in>='0'&&in<='9') { num*=10,num+=in-'0'; } if(IsN) num=-num; return true; } int n, s, t; int main() { // freopen("in", "r", stdin); while(scan_d(n) && scan_d(s) && scan_d(t)) { if(s == t && n != 1) printf("-1\n"); else if((s == 1 && t == n) || (s == n && t == 1)) printf("0\n"); else if(s == 1 || s == n || abs(s - t) == 1) printf("1\n"); else printf("2\n"); } }
[HDOJ5524]Subtree
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5524
问一棵完全二叉树有多少种子树包含的节点数量不同。
首先可以肯定的是,一棵完全二叉树有可能是满二叉树,满二叉树的子树依然是满二叉树。但是完全二叉树的子树有一棵是满二叉树,另一棵是完全二叉树。根据给定节点数量很轻易可以知道左右子树的形态,然后递归求解。n的数量太大要用long long。
#include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include <climits> #include <complex> #include <fstream> #include <cassert> #include <cstdio> #include <bitset> #include <vector> #include <deque> #include <queue> #include <stack> #include <ctime> #include <set> #include <map> #include <cmath> using namespace std; typedef long long ll; ll n; set<ll> ans; void dfs(ll x) { if(x == 0 || ans.count(x) > 0) { return; } ans.insert(x); if(--x % 2 == 0) { dfs(x / 2); } else { dfs(x / 2); dfs(x / 2 + 1); } } int main() { // freopen("in", "r", stdin); while(~scanf("%I64d", &n)) { ans.clear(); dfs(n); printf("%d\n", ans.size()); } return 0; }
相关文章推荐
- PHP(Hypertext Preprocessor)
- C#集合u
- 解决Hadoop 2.7.1无法加载本地库问题
- AIC准则选三个变量的r语言代码
- openStack 初步学习
- HDU 5525 Product
- hdu 1045 Fire Net
- Local Reference and Global Reference
- hdoj--1028--Ignatius and the Princess III(母函数)
- 单链表实现(1)
- 我决定采取策略
- HOJ-1005
- 《软件需求十步走》阅读笔记三
- hdoj--1028--Ignatius and the Princess III(母函数)
- Android 内存优化(1)
- grunt-watch
- 读大型网站架构设计
- 十大思想实验(思维风暴)
- Android动画基础-Tween和Frame动画
- 整理_03