Technocup 2017 - Elimination Round 1 A题
来源:互联网 发布:小时代讲的什么知乎 编辑:程序博客网 时间:2024/05/20 19:19
吐槽
今天真的是蠢哭了,A题错了2个小时,很强势。主要原因在于我认为这道题不用long long存也可以,但是事实并不是这样的,不用long long中途可能会tle,re,我用了深搜和广搜2种方法去写,但是还是写不出了,第五组错了,赛后数据一看,第五组是一个大数据,我发现了问题,改成long long后过了。留个文章提醒自己。。。
DFS版
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef long long LL;LL S[105], flag, h;void dfs(LL a, LL b){ if(a > b || flag) return ; if(a == b){ flag = 1; printf("YES\n%I64d\n", h); for(int i = 0; i < h; i++){ if(i) printf(" "); printf("%I64d", S[i]); } printf("\n"); return ; } S[h++] = 2*a; dfs(2*a, b); h--; S[h++] = 10*a+1; dfs(10*a+1, b); h--;}int main(){ LL a, b; while(scanf("%I64d%I64d", &a, &b) != EOF){ flag = h = 0; S[h++] = a; dfs(a, b); if(!flag) printf("NO\n"); } return 0;}
BFS 版
#include <queue>#include <cstdio>#include <vector>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef long long LL;LL a,b;vector <LL> vec;void bfs(){ priority_queue <LL, vector <LL>, greater<LL> > que; vec.clear(); que.push(a); vec.push_back(a); bool flag = false; while(!que.empty()){ LL cur = que.top(); que.pop(); if(2*cur < b) que.push(2*cur), vec.push_back(2*cur); else if(2*cur == b){ que.push(2*cur), vec.push_back(2*cur); flag = true; break;} if(10*cur+1 < b) que.push(10*cur+1), vec.push_back(10*cur+1); else if(10*cur+1 == b){ que.push(10*cur+1), vec.push_back(10*cur+1); flag = true; break;} } if(flag){ printf("YES\n"); int another[1005], cnt = 0; int cur = vec.size()-1; another[cnt++] = b; while(true){ for(int i = cur-1; i >= 0; i--){ if(vec[i]*2 == vec[cur] || vec[i]*10 + 1 == vec[cur]){ cur = i; another[cnt++] = vec[i]; break; } } if(!cur) break; } printf("%d\n", cnt); int first = 1; for(int i = cnt-1; i >= 0; i--) if(first) printf("%I64d", another[i]), first = 0; else printf(" %I64d", another[i]); printf("\n"); } else printf("NO\n");}int main(){ while(scanf("%I64d%I64d", &a, &b) != EOF){ bfs(); } return 0;}
0 0
- Technocup 2017 - Elimination Round 1 A题
- Technocup 2017 - Elimination Round 1
- Technocup 2017 - Elimination Round 1: Transformation: from A to B
- Technocup 2017 - Elimination Round 1 C 交互
- Technocup 2017 - Elimination Round 1 D 贪心
- Technocup 2017 - Elimination Round 1 C. Guess the Array (交互题)
- CF--Technocup 2017 - Elimination Round 2(ABCDE)
- Codeforces Round #434 (Div. 1, based on Technocup 2018 Elimination Round 1) A-C题解
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 – Elimination Round 2) A. Interview wi
- Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2) 解题报告
- Technocup 2017 - Elimination Round 1 (Rated for Div. 2) D. T-shirts Distribution 贪心、flows
- Technocup 2017 - Elimination Round 2 D. Sea Battle
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2) A-C题解
- Codeforces Round #454 (Div. 2, based on Technocup 2018 Elimination Round 4) A
- Codeforces Round #454 (Div. 2, based on Technocup 2018 Elimination Round 4) A-C
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination) A. Search for Pretty Integers
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2)
- Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2)
- volatile
- Android适配
- 使用cookie实现一周内自动登录
- Spring源码解析——如何阅读源码
- try catch finally
- Technocup 2017 - Elimination Round 1 A题
- Android Service的启动过程
- http中14个常用状态码
- 找球号(三)
- 使用UIImagePickerController实现 iOS录像拍照
- Codeforces Round #376 (Div. 2) F Video Cards
- 编译器的优化问题
- hdu1155Bungee Jumping+物理数学计算
- 中地数码集团笔试题