【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

枚举一个秤砣的重量不变。
某一个秤砣的重量不变之后。
所有秤砣的重量就固定了。
因为它的兄弟节点的重量要和它一样。
则父亲节点的重量就是这个节点的两倍了。
以此类推可以得到所有节点的重量的值。
第i层应该的重量都是相同的。
用一个map[height][x]统计某层里面有多少个数字x即可。
这样只要循环层数次就好。
复杂度够过了。

【代码】

/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
*/
#include <bits/stdc++.h>
using namespace std; string s;
int n,total;
map <long long,int> mmap[20];
map <int,vector <int> > mmap2; void dfs(int l,int r,int dep){
if (s[l]=='['){
int now = 0,i = l+1; do{
switch (s[i]){
case '[':{
now++;
break;
}
case ']':{
now--;
break;
}
}
i++;
}while (now!=0);
// now==0;
while (s[i]!=',') i++;
// s[i]==','
dfs(l+1,i-1,dep+1),dfs(i+1,r-1,dep+1);
}else{
int x = 0;
for (int i = l;i <= r;i++) x = x*10 + s[i]-'0';
mmap[dep][x]++;
mmap2[x].push_back(dep);
total++;
}
} int main(){
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
int T;
cin >> T;
while (T--){
for(int i = 0;i<=18;i++) mmap[i].clear();
mmap2.clear();
total = 0;
cin >> s;
n = s.size();
int ans = -1;
if (s[0]!='['){
ans = 0;
}else{
dfs(0,n-1,0);
for (auto temp:mmap2){
long long x = temp.first;
auto v = temp.second;
for (auto dep:v){
int tempans = 0;
int now = dep;
long long xx = x;
while (xx<=(long long) 1e10 && now >= 0){
tempans += mmap[now][xx];
now--;
xx*=2;
}
xx = x;
now = dep;
while (xx%2==0 && now <= 18){
xx/=2;
now++;
tempans += mmap[now][xx];
}
if (ans==-1){
ans = total - tempans;
}else{
ans = min(ans,total-tempans);
}
}
}
}
cout << ans << endl;
}
return 0;
}

最新文章

  1. Entity Framework 6 Recipes 2nd Edition(12-8)译 -&gt; 重新获取一个属性的原始值
  2. 「LeetCode」全部题解
  3. 用CS的思维可以指导BS的项目吗?
  4. JArray数组每个JObject对象添加一个键值对
  5. JavaScript基础学习篇
  6. PHP中IP地址与整型数字互相转换详解
  7. u Calculate e 分类: HDU 2015-06-19 22:18 14人阅读 评论(0) 收藏
  8. MVC项目发布错误
  9. Java日期转换SimpleDateFormat格式大全(转)
  10. bzoj2584
  11. AD DIV 层的知识 和 行为特效
  12. c# 中事务处理
  13. 磁盘管理之inode与block
  14. c#全宇宙最牛的编程软件
  15. 新概念英语(1-109)A Good Idea
  16. 学习笔记之X分钟速成Python3
  17. Javaweb过滤器
  18. 数字图像处理的Matlab实现(3)—灰度变换与空间滤波
  19. Synchronizing timer
  20. JS编程题

热门文章

  1. windows无法连接到打印机 错误提示0x00000214
  2. Vue总结(一)
  3. VBA 字符串操作(基础篇)
  4. Web测试要点 做移动端的测试,也做web端的测试,甚至后面桌面端的测试和后台的测试也做了,基本上把我们产品各个端都玩了一轮
  5. 实现IE下兼容CSS3的圆角效果
  6. Safe and efficient allocation of memory
  7. C# ArcGIS Engine 使当前选中的操作失效(清除当前鼠标事件)
  8. 在OEL 5.4 32bit上使用yum install命令遇到的问题
  9. struts2 结合extjs实现的一个登录实例
  10. C++遍历目录+_finddata_t结构体用法