uva 12166 bfs
来源:互联网 发布:linux yum 安装 svn 编辑:程序博客网 时间:2024/06/18 05:16
这一题与白书上的一题关于天平的题目有些相似
uva839
#include <iostream>#include <cstdio>#include <cstring>using namespace std;bool solve(int& w){ int w1,w2,d1,d2; cin >> w1 >> d1 >> w2 >> d2; bool b1 = true,b2 = true; if(!w1) b1 = solve(w1); if(!w2) b2 = solve(w2); w = w1 + w2; return b1 && b2 && (w1*d1==w2*d2);}int main(){ int T,w; cin >> T; while(T--){ if(solve(w)) cout<<"YES\n";else cout<<"NO\n"; if(T) cout<<"\n"; } return 0;}
这一题一开始并不怎么会做,是看别人结题报告的。
在这里结题报告
里面关于算法讲解的十分清楚
下面是代码
#include <iostream>#include <cstdio>#include <cstdlib>#include <map> #include <algorithm>using namespace std;string line;map<long long,int> dic;int sum;void dfs(int depth,int s,int e){ if(line[s] == '['){ int pos = 0; for(int i = s+1 ; i < e;i++){ if(line[i] == '[') pos++; if(line[i] == ']') pos--; if(pos==0 && line[i]==','){ dfs(depth+1,s+1,i-1); dfs(depth+1,i+1,e-1); } } } else{ long long w = 0; for(int i=s;i<=e;i++) w=w*10 + line[i]-'0'; sum++; dic[w<<depth]++; }}int main(){ int T; cin >> T; while(T--){ dic.clear(); sum = 0; cin >> line; dfs(0,0,line.size()-1); int maxn = 0; for(map<long long,int>::iterator it = dic.begin(); it != dic.end(); ++it) maxn = max(maxn, it->second); cout<<sum-maxn<<endl; }}
1 0
- uva 12166 bfs
- uva 784(bfs)
- UVa 3721 - Islands 【bfs】
- uva 10603 倒水 bfs
- uva 10603 - Fill bfs
- uva 11624(BFS)
- uva 10047(BFS)
- UVA 11624 BFS Fire
- UVa Fire! 11624 (BFS)
- 双向BFS--Uva-11624
- UVA 10047 独轮车(BFS)
- uva 11624 - Fire! bfs
- UVa 11624 Fire! / BFS
- uva 1377 - Ruler(BFS)
- UVA 10603 - Fill BFS~
- uva 439(bfs)
- Dungeon Master uva BFS
- XYZZY uva BFS+DFS
- C-教师比较排序。。
- 完成端口模型
- Android传感器开发基本流程
- Codeforces Round #304 (Div. 2)
- 4-7
- uva 12166 bfs
- linux awk命令详解
- hdu 1594 树状数组 水题
- 第十二周:程序填空
- kvm内存虚拟化及其实现
- .NET版三层登录问题集锦
- 青蛙跳台阶
- padding与margin区别
- 信息安全领域相关术语介绍