本文整理汇总了C++中ST类的典型用法代码示例。如果您正苦于以下问题:C++ ST类的具体用法?C++ ST怎么用?C++ ST使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ST类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: countDescendants
vector <string> countDescendants(vector <string> parentData)
{
f = true;
vector <string> ret, fail;
ST tmp = "";
tr(it, parentData) tmp += *it;
while(tmp.length() > 0)
{
int idx = tmp.find(' ');
vs.pb(tmp.substr(0, idx));
if(idx == string::npos) break;
tmp = tmp.substr(idx+1);
}
sort(all(vs));
vs.resize(unique(all(vs)) - vs.begin());
tr(it, vs)
{
int idx = it->find(',');
ST ch = it->substr(0, idx), par = it->substr(idx+1);
cnt[ch] = cnt[par] = 0;
g[par].pb(ch);
}
示例2: main
int main()
{
int N;
ST st;
cin >> N >> st;
map <char, int> mp;
forn(i, st.size())
mp[st[i]]++;
ST ret;
tr(it, mp) {
if(it->second % N != 0 ) {
cout << -1 << endl;
return 0;
}
forn(i, it->second/N)
ret += it->first;
}
forn(i, N)
cout << ret;
cout << endl;
return 0;
}
示例3: set_data_costs
/** Set the data costs of the MRF. */
void
set_data_costs(std::vector<FaceInfo> const & face_infos, ST const & data_costs,
std::vector<mrf::Graph::Ptr> const & mrfs) {
/* Set data costs for all labels except label 0 (undefined) */
for (std::size_t i = 0; i < data_costs.rows(); i++) {
ST::Row const & data_costs_for_label = data_costs.row(i);
std::vector<std::vector<mrf::SparseDataCost> > costs(mrfs.size());
for(std::size_t j = 0; j < data_costs_for_label.size(); j++) {
const std::size_t id = data_costs_for_label[j].first;
const float data_cost = data_costs_for_label[j].second;
const std::size_t component = face_infos[id].component;
const std::size_t cid = face_infos[id].id;
//TODO change index type of mrf::Graph
costs[component].push_back({static_cast<int>(cid), data_cost});
}
int label = i + 1;
for (std::size_t j = 0; j < mrfs.size(); ++j) {
mrfs[j]->set_data_costs(label, costs[j]);
}
}
for (std::size_t i = 0; i < mrfs.size(); ++i) {
/* Set costs for undefined label */
std::vector<mrf::SparseDataCost> costs(mrfs[i]->num_sites());
for (std::size_t j = 0; j < costs.size(); j++) {
costs[j].site = j;
costs[j].cost = MRF_MAX_ENERGYTERM;
}
mrfs[i]->set_data_costs(0, costs);
}
}
示例4: escapeCStringTpl
inline ST escapeCStringTpl(const ST &ba)
{
ST ret;
ret.reserve(ba.length() * 2);
for (int i = 0; i < ba.length(); ++i) {
CT c = ba.at(i);
switch (c) {
case '\\': ret += "\\\\"; break;
case '\a': ret += "\\a"; break;
case '\b': ret += "\\b"; break;
case '\f': ret += "\\f"; break;
case '\n': ret += "\\n"; break;
case '\r': ret += "\\r"; break;
case '\t': ret += "\\t"; break;
case '\v': ret += "\\v"; break;
case '"': ret += "\\\""; break;
default:
if (c < 32 || c == 127) {
ret += '\\';
ret += '0' + (c >> 6);
ret += '0' + ((c >> 3) & 7);
ret += '0' + (c & 7);
} else {
ret += c;
}
}
示例5: QScriptValue
QScriptValue convert_script_value_f_size<ST>::operator()(QScriptEngine*eng,
const ST & s) const
{
QScriptValue obj = eng->newObject();
obj.setProperty("width", QScriptValue(eng, s.width()));
obj.setProperty("height", QScriptValue(eng, s.height()));
return obj;
}
示例6: countInv
int countInv(ST st) {
int ret = 0;
forn(i, st.size())
forab(j, i+1, st.size() - 1)
if(st[j] < st[i])
ret++;
return ret;
}
示例7: add
int PermutationSum::add (int n)
{
SS ss;
ss << n;
ST st;
st = ss.str();
sort(all(st));
cout << ss.str() << endl;
int ret = 0;
do {
ret += atoi(st.c_str());
} while(next_permutation(all(st)));
return ret;
}
示例8: main
int main(){
scanf("%d%d", &N, &Q);
M = 1;
while(M < N) M <<= 1;
ST st = ST();
for(int i = 0; i < N; i++){
int h; scanf("%d", &h);
st.update(h, i);
}
while(Q--){
int a, b; scanf("%d%d", &a, &b);
a--;
// cerr << a << " " << b << " " << st.get_max(a,b) << " " << st.get_min(a,b) << endl;
printf("%d\n", st.get_max(a,b)-st.get_min(a,b));
}
return 0;
}
示例9: isolate_unseen_faces
/** Remove all edges of nodes which corresponding face has not been seen in any texture view. */
void
isolate_unseen_faces(UniGraph * graph, ST const & data_costs) {
int num_unseen_faces = 0;
for (std::uint32_t i = 0; i < data_costs.cols(); i++) {
ST::Column const & data_costs_for_face = data_costs.col(i);
if (data_costs_for_face.size() == 0) {
num_unseen_faces++;
// get all the adjacent facets of the i-the facet // each facet is corresponding to
// the a node in the UnifindGraph
std::vector<std::size_t> const & adj_nodes = graph->get_adj_nodes(i);
for (std::size_t j = 0; j < adj_nodes.size(); j++)
graph->remove_edge(i, adj_nodes[j]);
}
}
std::cout << "\t" << num_unseen_faces << " faces have not been seen by a view." << std::endl;
}
示例10: main
int main()
{
setlocale( LC_ALL, "Russian" );
ST obj;
cout << "Введите значение х (количество элементов в первом массиве): " << endl;
int x;
cin >> x;
if(x <= 0)
{
cout << "х должен быть положительным числом! " << endl;
}
else
{
cout << endl;
cout << "Начальный массив: " << endl;
obj.set(x);
cout << "Массив после сортировки: " << endl;
obj.sort(x);
}
getch();
return 0;
}
示例11: main13123131
int main13123131(int argc, const char * argv[])
{
srand((unsigned)time(NULL));
int N;
N = 100000;
clock_t begin,end;
ST st;
for (int i=0;i<N;i++)
{
Item it;
it.rand();
// cout<<it.key()<<" "<<it.INFO()<<endl;
st.insert(it);
}
Key v = 0;
double result = 0;
for (int i = 0; i < 10000; i++) {
v=1 + (int) (element * (::rand() / (RAND_MAX + 1.0)));
begin = clock();
st.search(v);
end = clock();
double t = double (end-begin)/CLOCKS_PER_SEC * 1000;
result += t;
}
result=result/10000*1000;
cout<<"ST contains: "<<st.count()<<" elements"<<endl;
// if (result.null())
// cout<<"Can not find the Key:"<<v;
// else
// cout<<"Key: "<<result.key()<<" Value:"<<result.INFO();
// double timeConsumed_ = double (end-begin)/CLOCKS_PER_SEC * 1000;
cout<<endl<<result<<" ms";
return 0;
}
示例12: maxCities
int maxCities(int n, vector<int> a, vector<int> b, vector<int> len) {
if (n <= 2) return n;
vector<vector<int>> adjNode(n);
for (int i = 0; i < n-1; ++i) {
--a[i];
--b[i];
adjNode[a[i]].push_back(b[i]);
adjNode[b[i]].push_back(a[i]);
distMap[{a[i], b[i]}] = len[i];
distMap[{b[i], a[i]}] = len[i];
}
int maxCount = 2;
for (int i = 0; i < n; ++i) {
Mii m;
for (int j : adjNode[i]) {
Si s;
// node, parent
ST<Pii> st;
Vi d(n, -1);
d[i] = 0;
st.emplace(j, i);
while (!st.empty()) {
Pii p = st.top();
d[p.first] = dist(p.first, p.second) + d[p.second];
s.insert(d[p.first]);
st.pop();
for (int k : adjNode[p.first]) {
if (k == p.second) continue;
st.emplace(k, p.first);
}
}
for (int dd : s) {
if (m.count(dd)) {
++m[dd];
} else m[dd] = 1;
}
}
for (Pii t : m) {
if (t.second > maxCount) maxCount = t.second;
}
}
return maxCount;
}
示例13: bar
// CK2-LABEL: _Z3bari
int bar(int arg){
ST<int> A;
return A.foo(arg);
}
示例14: present
#define pb push_back
#define present(x, c) ((c).find(x) != (c).end()) //map & set//
#define cpresent(x, c) (find( (c).begin(), (c).end(), x) != (c).end()) //vector & list//
#define read(n) scanf("%d", &n)
#define write(n) printf("%d ", n)
#define writeln(n) printf("%d\n", n)
#ifdef DEBUG
#undef DEBUG
#endif
#define DEBUG
ST s, t;
vi mx, mn;
vector <bool> in;
int main()
{
cin >> s >> t;
DEBUG(s);
DEBUG(t);
mx.resize(s.size(), 0);
mn.resize(s.size(), t.size());
in.resize(s.size(), false);
if(s.size() < t.size() || s.front() != t.front() || s.back() != t.back()) {
DEBUG("#0");
示例15: maintest
int maintest()
{
srand((unsigned)time(NULL));
// clock_t begin,end;
/* ST st;
//INSERT ELEMENTS
for (int i=0;i<N;i++)
{
Item it(i,i*0.1);
// cout<<it.key()<<" "<<it.INFO()<<endl;
st.insert(it);
}
Key v = 0;
double result = 0;
for (int i = 0; i < repeat; i++) {
v=1 + (int) (N * (::rand() / (RAND_MAX + 1.0)));
begin = clock();
st.search(v).INFO();
end = clock();
double t = double (end-begin)/CLOCKS_PER_SEC * 1000;
result += t;
}
result=result/repeat;
cout<<"ST contains: "<<st.count()<<" elements"<<endl;
cout<<"The search cost "<<result<<" ms";
*/
/*
Binary search st
*/
int key_[N];
float val_[N];
for (int i=0; i<N ; i++) {
key_[i] = 0;
val_[i] = 0;
}
ST bsst;
for (int i=0; i<N; i++) {
Item item(i,i*0.1);
//insert items
if (binarysearch2(item.key(),0, bsst.count(),key_) == -1) {
int j=bsst.count();
while(item.key()<key_[j-1]) {
if(j==0)
break;
key_[j]=key_[j-1];
val_[j]=val_[j-1];
j--;
}
key_[j]=item.key();
val_[j]=item.INFO();
}
else {
val_[binarysearch2(item.key(),0, bsst.count(),key_)] = item.INFO();
}
bsst.insert(item);
}
Key v = 0;
double result = 0;
clock_t begin,end;
begin = clock();
for (int i = 0; i < repeat; i++) {
v=1 + (int) (N * (::rand() / (RAND_MAX + 1.0)));
Item x = bsst.search(N/2);
}
end = clock();
result=double (end-begin)/CLOCKS_PER_SEC * 1000;
cout<<"ST contains: "<<bsst.count()<<" elements"<<endl;
cout<<"The search cost "<<result<<" ms";
result = 0;
int max = bsst.count()-1;
begin = clock();
for (int i=0; i <repeat; i++) {
v=1 + (int) (N * (::rand() / (RAND_MAX + 1.0)));
binarysearch2(max,0, max,key_);
}
end = clock();
result=double (end-begin)/CLOCKS_PER_SEC * 1000;
// result=result/repeat;
cout<<endl<<"BSST contains: "<<bsst.count()<<" elements"<<endl;
cout<<"The search cost "<<result<<" ms";
return 0;
}