Files
OI-source/2.12166.cpp
2023-08-03 09:22:52 +08:00

56 lines
1.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <iostream>
#include <string>
#include <map>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
string line;
map<LL,int> base; //LL±íʾ×ÜÖØÁ¿£¬int±íʾ³öÏֵĴÎÊý
int sum;
void dfs(int depth,int s, int e)
{
if(line[s]=='[')
{
int p=0;
for(int i=s+1;i!=e;++i)
{
if(line[i]=='[')++p;
if(line[i]==']')--p;
if(p==0&&line[i]==',')
{
dfs(depth+1,s+1,i-1);
dfs(depth+1,i+1,e-1);
}
}
}
else
{
LL w =0;
for(int i=s;i<=e;++i) w=w*10+line[i]-'0';
++sum;++base[w<<depth];
//³ÓíȵÄ×ÜÖØÁ¿(w<<depth)³öÏֵĴÎÊý+1£¬³ÓíÈ×ÜÊý(sum)+1£»
}
}
int main()
{
#ifdef local
freopen("pro.in","r",stdin);
#endif
ios::sync_with_stdio(false); //È¡ÏûcinºÍstdinͬ²½£¬Ê¹µÃcinËÙ¶ÈÏ൱ÓÚscanf
int T;
cin>>T;
while(T--)
{
cin>>line;
base.clear(); //Çå¿Õmap
sum =0; //×ÜÊýÇåÁã
dfs(0,0,(int)line.size()-1);
int maxn=0;
for(auto it = base.begin();it != base.end(); ++it)
maxn = max(maxn,it->second);
cout<<sum-maxn<<endl;
}
return 0;
}