本文整理汇总了C++中set::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ set::begin方法的具体用法?C++ set::begin怎么用?C++ set::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类set
的用法示例。
在下文中一共展示了set::begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
freopen("secure.in", "r", stdin);
freopen("secure.out", "w", stdout);
scanf("%d%d", &n, &m);
for (i = 1; i <= n; i++)
{
scanf("%d", &clr[i]);
if (clr[i] == 1)
odd++;
else
if (clr[i] == 2)
even++;
}
for (i = 1; i <= m; i++)
{
scanf("%d%d%d", &u, &v, &c);
//if (clr[u] != clr[v] || (clr[u] == 0 && clr[v] == 0))
//{
add(u, v, c);
add(v, u, c);
// }
}
inf = 1000*1000*1000;
inf *= 1000;
from = 1;
if (even < odd)
from = 2;
ans = inf;
for (i = 1; i <= n; i++)
if (clr[i] == from)
{
for (j = 1; j <= n; j++)
d[j] = inf;
d[i] = 0;
s.insert(make_pair(d[i], i));
while (!s.empty())
{
u = s.begin() -> second;
s.erase(make_pair(d[u], u));
j = st[u];
while (j != 0)
{
int v = data[j];
if (d[v] > d[u] + w[j])
{
s.erase(make_pair(d[v], v));
d[v] = d[u] + w[j];
s.insert(make_pair(d[v], v));
}
j = nxt[j];
}
}
for (j = 1; j <= n; j++)
if (clr[j] != from && clr[j] != 0)
if (d[j] < ans)
{
ans = d[j];
x = i;
y = j;
}
}
if (ans != inf)
printf("%d %d %d", x, y, ans);
else
printf("%d", -1);
return 0;
}
示例2: gornasredniaiden
void gornasredniaiden()
{
printf("%d/1 ",*unikaty.begin());
}
示例3: TrainRetentionModel
/* train a retention model; the svr_index is given as a parameter */
int RetentionModel::TrainRetentionModel(const set<string> &aa_alphabet, const map<string, double> &index,
const bool normalized_rts, vector<PSMDescription*> &psms) {
if (VERB >= 4) {
cerr << "Training retention model..." << endl;
}
// normalize
if (!normalized_rts) {
PSMDescriptionDOC::setPSMSet(psms);
sub_ = PSMDescriptionDOC::normSubRT_;
div_ = PSMDescriptionDOC::normDivRT_;
PSMDescriptionDOC::normalizeRetentionTimes(psms);
}
// set the amino acids alphabet and the index
vector<string> alphabet(aa_alphabet.begin(), aa_alphabet.end());
retention_features_.set_amino_acids_alphabet(alphabet);
retention_features_.set_svr_index(index);
// set the active features; this should be modified as we add more feature groups
bitset<RetentionFeatures::NUM_FEATURE_GROUPS> tmp;
if (index.size() <= 20) {
retention_features_.set_active_feature_groups(
tmp.set(RetentionFeatures::INDEX_NO_PTMS_GROUP));
} else {
retention_features_.set_active_feature_groups(
tmp.set(RetentionFeatures::INDEX_PHOS_GROUP));
}
// compute the amino acid features
retention_features_.ComputeRetentionFeatures(psms);
// normalize the features
NormalizeFeatures(true, psms);
// save the sub and the div
vsub_ = the_normalizer_->GetVSub();
vdiv_ = the_normalizer_->GetVDiv();
/*
//MT: prints the normalized features for Xuanbin's project
for (size_t j = 0; j < psms.size(); ++j) {
cout << psms[j].peptide;
for (int i = 0; i < retention_features_.GetTotalNumberFeatures(); ++i) {
cout << " " << psms[j].getRetentionFeatures()[i];
}
cout << std::endl;
}
cerr << "Finished printing out features" << std::endl;
*/
// initialize a RBF SVR
if (svr_model_) {
delete svr_model_;
}
InitSVR(false);
// calibrate the model
int number_features = retention_features_.GetTotalNumberFeatures();
//cout << number_features << endl;
//cout << psms[0] << endl;
svr_model_->CalibrateModel(psms, number_features);
// train the model
svr_model_->TrainModel(psms, number_features);
// unnormalize the retention time
PSMDescriptionDOC::unnormalizeRetentionTimes(psms);
if (VERB >= 4) {
cerr << "Done." << endl << endl;
}
return 0;
}
示例4: main
int main() {
//ios_base::sync_with_stdio(false);
FastInput input;
int nCases = input.readNextUnsigned();
for(int caseNum=1;caseNum<=nCases;++caseNum) {
int N = input.readNextUnsigned();
int M = input.readNextUnsigned();
int A = input.readNextUnsigned();
int nEdges = 0;
int myMaxWeight = 0;
int myMinWeight = 1000000;
for(int i=0;i<M;++i) {
int u = input.readNextUnsigned();
int v = input.readNextUnsigned();
int w = input.readNextUnsigned();
--u;--v;
if (w >= A) continue;
edges.insert(make_pair(w,make_pair(u,v)));
//edgesCounting[w].push_back(make_pair(u,v));
//myMaxWeight = max(myMaxWeight, w);
//myMinWeight = min(myMinWeight, w);
//adj[v].push_back({u,w});
}
UnionFind uf(N);
//sort in linear time
/*
weightTotal = 0;
for(int weight = myMinWeight; weight<=myMaxWeight;++weight) {
for(int j=0;j<edgesCounting[weight].size();++j) {
int xroot = uf.find(edgesCounting[weight][j].first);
int yroot = uf.find(edgesCounting[weight][j].second);
if (xroot != yroot) {
uf.Union(xroot,yroot);
weightTotal += weight;
}
}
edgesCounting[weight].clear();
}
*/
weightTotal = 0;
//sort(edges,edges + nEdges); //stable sort
while (edges.size()) {
auto temp = edges.begin();
int w = temp->first;
int xroot = uf.find(temp->second.first);
int yroot = uf.find(temp->second.second);
edges.erase(temp);
if (xroot != yroot) {
uf.Union(xroot,yroot);
weightTotal += w;
}
}
/*
for(int i=0;i<nEdges;++i) {
int xroot = uf.find(edges[i].second.first);
int yroot = uf.find(edges[i].second.second);
if (xroot != yroot) {
uf.Union(xroot,yroot);
weightTotal += edges[i].first;
}
}
*/
nComponents = 0;
for(int i=1;i<=N;++i) {
int place = uf.find(i);
if (!mySet[place]) {
++nComponents;
mySet[place] = 1;
}
}
mySet = 0;
int ans = weightTotal + A * nComponents;
cout << "Case #" << caseNum << ": " << ans << " " << nComponents << '\n';
}
return 0;
}
示例5: cmp1
bool cmp1(set<int>& a, set<int>& b) {
return *a.begin() < *b.begin();
}
示例6: main
int main()
{
//freopen("in.txt", "r", stdin);
ios_base::sync_with_stdio(0);
cin.tie(0);
int h, q, i, k;
long long l, r, lo = 1, hi = 2;
vector <pair <long long, long long> > v, v1;
cin >> h >> q;
for(int i = 0; i < h - 1; i++)
{
lo *= 2;
hi *= 2;
}
hi--;
s.insert({lo, hi});
while(q--)
{
// for(auto it = s.begin(); it != s.end(); it++)
// cout << it -> first << " " << it -> second << " ";
//cout << "\n";
v.clear();
v1.clear();
cin >> i >> l >> r >> k;
for(int j = i; j < h; j++)
{
l *= 2;
r = r*2 + 1;
}
if(k == 1)
{
auto it = s.upper_bound({l, l}), it2 = s.upper_bound({r, hi + 1});;
if(it != s.begin())
it--;
for(it; it != it2; it++)
{
long long l1 = it -> first, r1 = it -> second;
if(l <= r1 && l1 <= r)
v.push_back({max(l, l1), min(r, r1)});
}
s.clear();
}
else
{
auto it = s.upper_bound({l, l}), it2 = s.upper_bound({r, hi + 1});;
if(it != s.begin())
it--;
for(it; it != it2; it++)
{
long long l1 = it -> first, r1 = it -> second;
if(l <= r1 && l1 <= r)
{
long long l2 = max(l, l1), r2 = min(r, r1);
v1.push_back({l1, r1});
if(l1 < l2 && r2 < r1)
{
v.push_back({l1, l2 - 1});
v.push_back({r2 + 1, r1});
}
else if(r2 == r1 && l1 != l2)
v.push_back({l1, l2 - 1});
else if(l1 == l2 && r1 != r2)
v.push_back({r2 + 1, r1});
}
}
}
for(int j = 0; j < v1.size(); j++)
s.erase(v1[j]);
for(int j = 0; j < v.size(); j++)
s.insert(v[j]);
}
long long ans = -1;
if(s.empty())
{
cout << "Game cheated!";
return 0;
}
else if(s.size() == 1)
{
auto it = s.begin();
if(it -> first == it -> second)
{
cout << s.begin() -> first;
return 0;
}
}
cout << "Data not sufficient!";
return 0;
}
示例7: getDecompositionsDAC_
// divide and conquer algorithm of the sequencing
void CompNovoIdentificationCID::getDecompositionsDAC_(set<String> & sequences, Size left, Size right, DoubleReal peptide_weight, const PeakSpectrum & CID_spec, Map<DoubleReal, CompNovoIonScoringCID::IonScore> & ion_scores)
{
static DoubleReal oxonium_mass = EmpiricalFormula("H2O+").getMonoWeight();
DoubleReal offset_suffix(CID_spec[left].getPosition()[0] - oxonium_mass);
DoubleReal offset_prefix(peptide_weight - CID_spec[right].getPosition()[0]);
#ifdef DAC_DEBUG
static Int depth_(0);
++depth_;
String tabs_(depth_, '\t');
cerr << tabs_ << "void getDecompositionsDAC(sequences[" << sequences.size() << "], " << left << ", " << right << ") ";
cerr << CID_spec[left].getPosition()[0] << " " << CID_spec[right].getPosition()[0] << " diff=";
#endif
DoubleReal diff = CID_spec[right].getPosition()[0] - CID_spec[left].getPosition()[0];
#ifdef DAC_DEBUG
cerr << diff << endl;
cerr << "offset_prefix=" << offset_prefix << ", offset_suffix=" << offset_suffix << endl;
#endif
if (subspec_to_sequences_.has(left) && subspec_to_sequences_[left].has(right))
{
sequences = subspec_to_sequences_[left][right];
#ifdef DAC_DEBUG
depth_--;
cerr << tabs_ << "from cache DAC: " << CID_spec[left].getPosition()[0] << " " << CID_spec[right].getPosition()[0] << " " << sequences.size() << " " << left << " " << right << endl;
#endif
return;
}
// no further solutions possible?
if (diff < min_aa_weight_)
{
#ifdef DAC_DEBUG
depth_--;
#endif
return;
}
// no further division needed?
if (diff <= max_decomp_weight_)
{
vector<MassDecomposition> decomps;
// if we are at the C-terminus use precursor_mass_tolerance_
if (offset_prefix < precursor_mass_tolerance_)
{
Param decomp_param(mass_decomp_algorithm_.getParameters());
decomp_param.setValue("tolerance", precursor_mass_tolerance_);
mass_decomp_algorithm_.setParameters(decomp_param);
getDecompositions_(decomps, diff);
decomp_param.setValue("tolerance", fragment_mass_tolerance_);
mass_decomp_algorithm_.setParameters(decomp_param);
}
else
{
getDecompositions_(decomps, diff);
}
//filterDecomps_(decomps);
#ifdef DAC_DEBUG
cerr << tabs_ << "Found " << decomps.size() << " decomps" << endl;
cerr << tabs_ << "Permuting...";
#endif
//static Map<String, set<String> > permute_cache;
for (vector<MassDecomposition>::const_iterator it = decomps.begin(); it != decomps.end(); ++it)
{
#ifdef DAC_DEBUG
cerr << it->toString() << endl;
#endif
String exp_string = it->toExpandedString();
if (!permute_cache_.has(exp_string))
{
permute_("", exp_string, sequences);
permute_cache_[exp_string] = sequences;
}
else
{
sequences = permute_cache_[exp_string];
}
}
#ifdef DAC_DEBUG
cerr << tabs_ << CID_spec[left].getPosition()[0] << " " << CID_spec[right].getPosition()[0] << " " << peptide_weight << endl;
if (sequences.size() > max_subscore_number_)
{
cerr << tabs_ << "Reducing #sequences from " << sequences.size() << " to " << max_subscore_number_ << "(prefix=" << offset_prefix << ", suffix=" << offset_suffix << ")...";
}
#endif
// C-terminus
if (offset_suffix <= precursor_mass_tolerance_)
{
filterPermuts_(sequences);
}
//.........这里部分代码省略.........
示例8: algoritmo
chrono::microseconds algoritmo(unsigned int n, unsigned int m, unsigned int costoTotal, vector< list<Arista> > aristasDeCadaVertice, vector< list<Arista> > aristasDeCadaVerticeAGM, set<Arista, comparacionArista> aristasGrafo, set<Vertice> verticesAGM, set<Arista, comparacionArista> aristasAGM, set<Arista, comparacionArista> aristasCandidatasAGM, list<Arista> aristasAnillo)
{
auto start_time = chrono::high_resolution_clock::now();
// Arranco poniendo el vértice 0 en verticesAGM, y sus aristas en aristasCandidatasAGM
verticesAGM.insert(0);
for(auto it = aristasDeCadaVertice[0].begin(); it != aristasDeCadaVertice[0].end(); it++) {
aristasCandidatasAGM.insert(*it);
}
while (aristasAGM.size() < n - 1 && aristasCandidatasAGM.size() > 0 ) {
auto iterAristaMinima = aristasCandidatasAGM.begin();
Arista a = *iterAristaMinima;
aristasCandidatasAGM.erase(iterAristaMinima);
pair<bool,Vertice> infoIncidencia = a.incideEnDosVertices(verticesAGM);
if (infoIncidencia.first) {
continue;
} else {
Vertice nuevo = infoIncidencia.second;
verticesAGM.insert(nuevo);
aristasGrafo.erase(a);
aristasAGM.insert(a);
Vertice otro = a.dameElOtroVertice(nuevo);
aristasDeCadaVerticeAGM[nuevo].push_back(a);
aristasDeCadaVerticeAGM[otro].push_back(a);
for(auto it = aristasDeCadaVertice[nuevo].begin(); it != aristasDeCadaVertice[nuevo].end(); it++) {
if (it->incideEnDosVertices(verticesAGM).first) {
continue;
}
aristasCandidatasAGM.insert(*it);
}
}
}
if ( (aristasAGM.size() < n - 1) || (aristasGrafo.size() == 0)) {
// No hay solucion
} else {
Arista menor = *aristasGrafo.begin();
aristasAGM.insert(menor);
for (auto it = aristasAGM.begin(); it != aristasAGM.end(); it++) {
costoTotal += it->costo();
}
Vertice primero = menor.dameVerticeUno();
Vertice segundo = menor.dameVerticeDos();
aristasDeCadaVerticeAGM[primero].push_back(menor);
aristasDeCadaVerticeAGM[segundo].push_back(menor);
// Tengo que encontrar el circuito simple, esto es, el anillo
infoVerticeDFS info[n];
DFS_visit(aristasDeCadaVerticeAGM, info, primero);
if (info[primero].backEdges.size() != 1) {
cout << "Hay algo mal, el vertice deberia tener exactamente un back edge." << endl;
}
Arista backEdge = info[primero].backEdges.front();
aristasAnillo.push_back(backEdge);
aristasAGM.erase(backEdge);
Vertice actual = backEdge.dameElOtroVertice(primero);
while (actual != primero) {
aristasAGM.erase(info[actual].aristaAnterior);
aristasAnillo.push_back(info[actual].aristaAnterior);
actual = info[actual].verticeAnterior;
}
}
auto end_time = chrono::high_resolution_clock::now();
chrono::microseconds tiempo = chrono::duration_cast<chrono::microseconds>(end_time - start_time);
return tiempo;
}
示例9: extend
void extend(vector<vector<char>> &a, list<set<int>> &REZULT, set <int> candidates, set <int> not, set <int> M){
set <int> K, P;
int v, SIZE = a[1].size();
auto theIterator = candidates.begin();
while ((candidates.size() != 0) && check(a, candidates, not)){
K.clear();
P.clear();
for (auto it = not.begin(); it != not.end(); it++) { P.insert(*it); }
for (auto it = candidates.begin(); it != candidates.end(); it++) { K.insert(*it); }
v = *candidates.begin();
M.insert(v);
for (int i = 0; i < SIZE; i++)
{
if (!a[v][i])
{
theIterator = K.find(i);
if (theIterator != K.end())
{
K.erase(theIterator);
}
theIterator = P.find(i);
if (theIterator != P.end())
{
P.erase(theIterator);
}
}
}
theIterator = K.find(v);
if (theIterator != K.end())
{
K.erase(theIterator);
}
if ((P.size() == 0) && (K.size() == 0))
{
REZULT.push_back(M);
//if (REZULT.size()%100==0)
// cout << M.size() << " ";
if (M.size() >= max_size){
max_size = M.size();
cout << M.size() << " ";
show_clique(M, nv, nv);
}
if (M.size() >= CLIQUE_SIZE)
stop_flag = 1;
}
else{
if ((REZULT.size() < CLIQUES_COUNT) && (!stop_flag)){
//if (!stop_flag){
extend(a, REZULT, K, P, M);
}
else{
break;
}
}
theIterator = candidates.find(v);
if (theIterator != candidates.end())
{
candidates.erase(theIterator);
}
theIterator = M.find(v);
if (theIterator != M.end())
{
M.erase(theIterator);
}
not.insert(v);
}
}
示例10: main
int main()
{
ios_base::sync_with_stdio(0);
fill(rem_deg, 0);
fill(xor_all, 0);
fill(xor_done, 0);
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>rem_deg[i]>>xor_all[i];
if( rem_deg[i] > 0 )
Q.insert( mp(rem_deg[i],i) );
}
while( sz(Q) )
{
pii top = *Q.begin();
Q.erase(Q.find(top));
int curr_node = top.Y;
int rem_d = top.X;
if( rem_d == 0)
continue;
assert( rem_d == 1 );
int other = xor_all[curr_node] xor xor_done[curr_node];
ans.pb( mp(curr_node,other));
// cout<<curr_node<<" "<<other<<endl;
pii todel = mp( rem_deg[other] , other );
Q.erase( Q.find(todel) );
rem_deg[curr_node]=0;
rem_deg[other]--;
xor_all[curr_node] =0;
xor_all[other]= xor_all[other] xor curr_node;
if(rem_deg[other] > 0 )
Q.insert( mp( rem_deg[other] , other ) );
}
cout<<sz(ans)<<endl;
for(int i=0;i<sz(ans);i++)
cout<<ans[i].X<<" "<<ans[i].Y<<endl;
return 0;
}
示例11: printset
void printset(set<unsigned int> &m){
for(set<unsigned int>::iterator i = m.begin(); i != m.end(); i++)
cout << *i << " ";
}
示例12: main
int main( int argc, char* argv[ ] )
{
bool has_object_path = false;
string src_file_name, dependency_file_extension( "obj" );
string object_file_path;
if( argc < 2 || argc > 5 )
{
cout << c_title << '\n' << c_usage << endl;
return 0;
}
int argnum = 1;
while( argnum < argc - 1 )
{
string opt( argv[ argnum++ ] );
if( opt.size( ) < 2
|| ( opt.substr( 0, 2 ) != "-i" && opt.substr( 0, 2 ) != "/i"
&& opt.substr( 0, 2 ) != "-o" && opt.substr( 0, 2 ) != "/o"
&& opt.substr( 0, 2 ) != "-x" && opt.substr( 0, 2 ) != "/x" ) )
{
cerr << "Error: Unknown option '" << opt << "'." << endl;
return 1;
}
bool is_object_path = false;
bool is_include_path = false;
if( opt.substr( 0, 2 ) == "-o" || opt.substr( 0, 2 ) == "/o" )
is_object_path = true;
else if( opt.substr( 0, 2 ) == "-i" || opt.substr( 0, 2 ) == "/i" )
is_include_path = true;
opt.erase( 0, 2 );
if( is_object_path )
{
object_file_path = opt;
has_object_path = true;
transform_path_separators( object_file_path );
if( !object_file_path.empty( ) && object_file_path[ object_file_path.size( ) - 1 ] != '\\' )
object_file_path += '\\';
}
else if( is_include_path )
{
size_t pos = opt.find( ';' );
while( true )
{
include_paths.insert( opt.substr( 0, pos ) );
if( pos == string::npos )
break;
opt.erase( 0, pos + 1 );
pos = opt.find( ';' );
}
}
else
dependency_file_extension = opt;
}
src_file_name = argv[ argnum ];
size_t pos = src_file_name.find_last_of( '.' );
if( pos == string::npos )
{
cerr << "Error: Didn't find file extension in '" << src_file_name << "'." << endl;
return 1;
}
string object_file( src_file_name.substr( 0, pos ) );
if( has_object_path )
{
transform_path_separators( object_file );
pos = object_file.find_last_of( '\\' );
if( pos != string::npos )
object_file.erase( 0, pos + 1 );
object_file = object_file_path + object_file;
}
add_include_names( src_file_name );
object_file = object_file + '.' + dependency_file_extension;
cout << object_file << ":\\\n" << ' ' << src_file_name;
set< string >::iterator i;
for( i = include_names.begin( ); i != include_names.end( ); i++ )
cout << "\\\n " << *i;
cout << endl;
return 0;
}
示例13: add_include_names
void add_include_names( const string& file_name, bool is_root_file = true )
{
string path;
ifstream inpf( file_name.c_str( ) );
if( is_root_file && !inpf )
{
cerr << "Error: Unable to open source file '" << file_name << "' for input." << endl;
exit( 1 );
}
if( !is_root_file )
{
set< string >::iterator i;
for( i = include_paths.begin( ); i != include_paths.end( ); ++i )
{
string str( *i );
str += '\\';
str += file_name;
inpf.clear( );
inpf.open( str.c_str( ), ios::in );
if( inpf )
{
path = *i;
break;
}
}
if( !inpf )
{
cerr << "Error: Unable to open source file '" << file_name << "' for input." << endl;
exit( 1 );
}
string str( path );
if( !str.empty( ) )
str += '\\';
str += file_name;
transform_path_separators( str );
if( include_names.find( str ) != include_names.end( ) )
return;
include_names.insert( str );
size_t pos = str.find_last_of( '\\' );
if( pos != string::npos )
{
string current = str.substr( 0, pos );
if( include_paths.find( current ) == include_paths.end( ) )
include_paths.insert( current );
}
}
string line, include;
while( getline( inpf, line ) )
{
if( get_include_name( line, include ) )
add_include_names( include, false );
}
}
示例14: solve
int solve() {
generateFolds();
//bit rep of protein, 0: H, 1: P
int sum = 0;
concurrent_vector<int> maxBond;
parallel_for(0, 1 << LEN,
[&](int i) {
int head = LEN - 1, tail = 0;
int mirrorFactor = 1; //2 if mirror exists, 1 applies for HHHH, or PPPP
while (head > tail) {
bool h = i & (1 << head);
bool t = i & (1 << tail);
if (h == t) {
//could be palindrome, then we can not rely on mirror
tail++;
head--;
}
else {
//head != tail, a mirror exists
if (h < t) {
//we will calculate this one, and skip the other mirrored string
mirrorFactor = 2;
}
else {
return; //skip
}
break;
}
}
int maxNewBond = 0;
int fixed = countExistingBond(i);
int newBond;
for (auto fold = allFolds.begin(); fold != allFolds.end(); fold++) {
if (maxNewBond >= fold->size()) {
break; //impossible to beat the current best
}
newBond = countNewBonds(i, *fold);
maxNewBond = max(maxNewBond, newBond);
if (newBond == fold->size()) {
//all match, this is the best solution, because we search in order of number of new bonds
break;
}
}
maxBond.push_back((maxNewBond + fixed) * mirrorFactor);
});
sum = accumulate(maxBond.begin(), maxBond.end(), 0);
/* replaced by parallel_for
int nSkipped = 0;
int nPal = 0;
for (int i = 0; i < (1 << LEN); i++) {
int head = LEN - 1, tail = 0;
int mirrorFactor = 1; //2 if mirror exists, 1 applies for HHHH, or PPPP
bool skip = false;
while (head > tail) {
bool h = i & (1 << head);
bool t = i & (1 << tail);
if (h == t) {
//could be palindrome, then we can not rely on mirror
tail++;
head--;
}
else {
//head != tail, a mirror exists
if (h < t) {
//we will calculate this one, and skip the other mirrored string
mirrorFactor = 2;
}
else {
skip = true;
nSkipped++;
}
break;
}
}
if (skip) {
continue;
}
if (mirrorFactor == 1) {
nPal++;
}
int maxNewBond = 0;
int fixed = countExistingBond(i);
int newBond;
for (auto fold = allFolds.begin(); fold != allFolds.end(); fold++) {
if (maxNewBond >= fold->size()) {
break; //impossible to beat the current best
}
newBond = countNewBonds(i, *fold);
maxNewBond = max(maxNewBond, newBond);
if (newBond == fold->size()) {
//all match, this is the best solution, because we search in order of number of new bonds
break;
}
}
sum += (maxNewBond + fixed) * mirrorFactor;
//.........这里部分代码省略.........
示例15: print_dies
void print_dies(ostream &s, set<iterator_base> dies, optional<type_set&> types) {
for (auto iter = dies.begin(); iter != dies.end(); iter++) {
print_type_die(s, *iter, types);
s << endl << endl;
}
}