本文整理汇总了C++中multiset::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ multiset::empty方法的具体用法?C++ multiset::empty怎么用?C++ multiset::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiset
的用法示例。
在下文中一共展示了multiset::empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(){
int n, m, x;
while( scanf("%d%d", &n, &m) != EOF ){
st.clear();
for(int i=0 ; i < n ; ++i){
scanf("%d", &x);
st.insert(x);
}
for(int i=0 ; i < m ; ++i)
scanf("%d", &a[i].d);
for(int i=0 ; i < m ; ++i)
scanf("%d", &a[i].p);
if( m < n ){
puts("No"); continue;
}
sort( a, a+m, cmp );
LL ans = 0;
for(int i=0 ; i < m ; ++i){
it = st.upper_bound( a[i].d );
if( it != st.begin() ){
it--;
st.erase(it);
ans += a[i].p;
if( st.empty() ) break;
}
}
if( st.empty() ) printf("%I64d\n", ans);
else puts("No");
}
return 0;
}
示例2: main
int main() {
ifstream in; ofstream out;
in.open("input.txt"); out.open("output.txt");
int count=0;
in >> M >> N;
char t;
for(int i=0; i<M; i++){
in >> t;
parolaChars.insert(t);
}
in >> stringa;
for(int i=0; i<M; i++){
it = parolaChars.find (stringa[i]);
if(it!=parolaChars.end())
parolaChars.erase (it);
else
parolaCharsUnused.insert(stringa[i]);
}
if(parolaChars.empty())
count++;
for(int i=M; i<N; i++){
it = parolaCharsUnused.find (stringa[i-M]);
if(it!=parolaCharsUnused.end())
parolaCharsUnused.erase (it);
else
parolaChars.insert(stringa[i-M]);
it = parolaChars.find (stringa[i]);
if(it!=parolaChars.end())
parolaChars.erase (it);
else
parolaCharsUnused.insert(stringa[i]);
//cout << parolaChars.size() << " " << stringa[i-M] << " " << stringa[i] << endl;
if(parolaChars.empty())
count++;
}
out << count;
in.close(); out.close();
return 0;
}
示例3: adjust
void adjust(){
long long val;
if(!minset.empty()){
if(!maxset.empty()){
if(maxset.size() > minset.size()){
it = maxset.begin();
val = *it;
maxset.erase(it);
minset.insert(val);
adjust();
}
else if(minset.size() - maxset.size() > 1){
it = minset.end();
it--;
val = *it;
minset.erase(it);
maxset.insert(val);
adjust();
}
}
else{
if(minset.size() > 1){
it = minset.end();
it--;
val = *it;
minset.erase(it);
maxset.insert(val);
adjust();
}
}
}
else{
if(!maxset.empty()){
it = maxset.begin();
val = *it;
maxset.erase(it);
minset.insert(val);
adjust();
}
}
}
示例4: main
int main(){
int T, n;
scanf("%d", &T);
while( T-- ){
scanf("%d", &n);
for(int i=0 ; i < n ; ++i)
scanf("%d%d", &a[i].h, &a[i].w);
for(int i=0 ; i < n ; ++i)
scanf("%d%d", &b[i].h, &b[i].w);
sort( a, a+n, cmp );
sort( b, b+n, cmp );
st.clear();
int ans = 0;
for(int i=0,j=0 ; i < n ; ++i){
while( j < n && a[i].h >= b[j].h ){
st.insert(b[j].w);
j++;
}
it = st.upper_bound(a[i].w);
if( it != st.begin() && !st.empty() ){
--it;
st.erase(it);
ans++;
}
}
printf("%d\n", ans);
}
return 0;
}
示例5: main
int main()
{
scanf("%d", &t);
while(t--)
{
y.clear();
scanf("%d", &n);
for(int i = 0; i < n; ++i)
scanf("%d%d", &a[i].h, &a[i].w);
sort(a, a + n);
for(int i = 0; i < n; ++i)
scanf("%d%d", &b[i].h, &b[i].w);
sort(b, b + n);
ans = 0;
for(int i = 0, j = 0; i < n; ++i)
{
while(j < n && b[j].h <= a[i].h)
y.insert(b[j++].w);
if(y.empty())
continue;
multiset<int>::iterator it = y.upper_bound(a[i].w);
if(it != y.begin())
{
y.erase(--it);
++ans;
}
}
printf("%d\n", ans);
}
return 0;
}
示例6: encodeAllSymbols
void encodeAllSymbols(){
if (treeSet.empty()) {
return;
}
string pattern;
HuffmanNode* root = *(treeSet.rbegin());
_encodeAllSymbols(pattern, root);
}
示例7: PerformInsert
/* Function: PerformInsert(int value,
* multiset<int>& minSet,
* multiset<int>& maxSet)
* Usage: bool success = PerformInsert(value, minSet, maxSet);
* -----------------------------------------------------------------------------
* Inserts one instance of the specified value into the minset or the maxset,
* according to the following logic: if the value exceeds the current maximum
* value in the minset, then add the value to the maxset; otherwise, add the
* value to the minset. The function returns true if the insert operation was
* successful, and false otherwise.
*/
bool PerformInsert(int value, multiset<int>& minSet, multiset<int>& maxSet)
{
if (minSet.empty() || value <= *FindMaxElement(minSet))
minSet.insert(value);
else
maxSet.insert(value);
/* Always return true. */
return true;
}
示例8: change
void change(int x){
int t;
typeof(S.begin()) it;
if(col[x])er(S,mp(x,0));else S.insert(mp(x,0));
for(col[x]^=1;x;x=jump[x]){
n=bel[x];
if(jump[x]&&!S.empty()){
it=S.find(mp(jump[x],Gm(D1,sl[n],sl[n+1]-1)-sl[n]+1));
if(it!=S.end())S.erase(it);
}
if(!S.empty()){
it=S.lower_bound(mp(x,-INF));
t=(it!=S.end()&&it->first==x)?it->second:INF;
}else t=INF;
D0[pos[x]+tn-1]=t-pos[x],D1[pos[x]+tn-1]=t+pos[x];
for(t=(pos[x]+tn-1)>>1;t;t>>=1)
D0[t]=max(D0[L(t)],D0[R(t)]),D1[t]=max(D1[L(t)],D1[R(t)]);
if(jump[x])
S.insert(mp(jump[x],Gm(D1,sl[n],sl[n+1]-1)-sl[n]+1));
}
}
示例9: Dijkstra
inline int Dijkstra()
{
for (unsigned short int i = 1; i <= n; i++)
{
noduri[i].vizitat = false; //Nu am vizitat nici und nod
noduri[i].cost = INFINIT; //Costul pt. a ajunge la restul nodurilor e infinit
}
short int nod_curent = sursa;
noduri[sursa].cost = 0; //Costul pt. a ajunge la sursa e 0
lista.insert(sursa);
while (lista.empty() == false)
{
//Cautam nodul nevizitat cel mai apropiat de sursa
nod_curent = *lista.begin();
lista.erase(lista.begin());
noduri[nod_curent].vizitat = false; //Marcam nodul curent ca nevizitat(in cazul revenirii pe un alt drum)
for (unsigned short int i = 0; i < noduri[nod_curent].vecini.size(); i++) //Parcurgem toti vecinii nodului curent
{
if (capacitate[nod_curent][noduri[nod_curent].vecini[i].b] > flux[nod_curent][noduri[nod_curent].vecini[i].b])
{
if ((noduri[nod_curent].cost + noduri[nod_curent].vecini[i].cost) < noduri[noduri[nod_curent].vecini[i].b].cost)
{
noduri[noduri[nod_curent].vecini[i].b].cost = noduri[nod_curent].cost + noduri[nod_curent].vecini[i].cost;
drum[noduri[nod_curent].vecini[i].b] = nod_curent; //In acest vecin ajungem din nodul curent
if (noduri[noduri[nod_curent].vecini.at(i).b].vizitat == false)
{
noduri[noduri[nod_curent].vecini.at(i).b].vizitat = true;
lista.insert(noduri[nod_curent].vecini[i].b); //Adaugam vecinul in coada
}
}
}
}
}
if (noduri[destinatie].cost < INFINIT)
{
drum_ameliorare = true;
int capacitate_reziduala = INFINIT;
for (nod_curent = destinatie; nod_curent != sursa; nod_curent = drum[nod_curent])
if (capacitate_reziduala > (capacitate[drum[nod_curent]][nod_curent] - flux[drum[nod_curent]][nod_curent]))
capacitate_reziduala = capacitate[drum[nod_curent]][nod_curent] - flux[drum[nod_curent]][nod_curent];
for (nod_curent = destinatie; nod_curent != sursa; nod_curent = drum[nod_curent])
{
flux[nod_curent][drum[nod_curent]] -= capacitate_reziduala;
flux[drum[nod_curent]][nod_curent] += capacitate_reziduala;
}
return noduri[destinatie].cost * capacitate_reziduala;
}
else
{
drum_ameliorare = false;
return 0;
}
}
示例10: test
bool test(int first, multiset<int> s){
int idx = 0, z;
multiset<int>::iterator it;
a[idx++] = first;
while(!s.empty()){
z = *s.begin() - first;
FOR(i, idx){
if((it = s.find(z + a[i])) == s.end()) return false;
s.erase(it);
}
a[idx++] = z;
}
return true;
}
示例11: PerformSingleOperation
/* Function: PerformSingleOperation(string operation,
* int value,
* multiset<int>& minSet,
* multiset<int>& maxSet)
* Usage: string median = PerformSingleOperation(op, x, minSet, maxSet)
* -----------------------------------------------------------------------------
* Performs the specified operation (insert or remove) with the specified value,
* and returns a formatted string representation of the new median value after
* performing the operation.
*/
string PerformSingleOperation(string operation, int value,
multiset<int>& minSet, multiset<int>& maxSet)
{
bool operationSucceeded;
/* Handle an insert operation. */
if (operation == kInsertOperation)
operationSucceeded = PerformInsert(value, minSet, maxSet);
/* Handle a delete operation. */
else if (operation == kDeleteOperation)
operationSucceeded = PerformDelete(value, minSet, maxSet);
/* Resize each set to be of size n/2. */
ResizeSets(minSet, maxSet);
/* Return an error message if necessary. */
if (!operationSucceeded || (minSet.empty() && maxSet.empty()))
return kErrorMessage;
/* Otherwise return the median as a string. */
return GetFormattedMedian(minSet, maxSet);
}
示例12: check
bool check()
{
if(tcnt < st.size()) return 0 ;
scnt=0 ;
for(int i=0;!st.empty() && i<tcnt;i++)
{
auto it=st.upper_bound(tmp[i]) ;
if(it!=st.begin())
it-- , st_tmp[scnt++]=*it , st.erase(it) ;
}
int sz=st.size() ;
for(int i=0;i<scnt;i++) st.insert(st_tmp[i]) ;
return sz==0 ;
}
示例13: main
int main()
{
int t,x;
gint(t);
while(t--)
{
while(!s1.empty())
s1.erase(s1.begin());
while(!s2.empty())
s2.erase(s2.begin());
while(1)
{
gint(x);
if(x==0)
break;
else if(x==-1)
median_ele();
else if(x>0)
add_ele(x);
}
}
return 0;
}
示例14: solve
void solve() {
sort(c, c + n);
sort(g, g + m);
for(int i = 0; i < m; i ++)
if(tmpCost != g[i].cost) {
calc(tmpCost);
tmpCost = g[i].cost;
grass.push(g[i]);
}
else grass.push(g[i]);
calc(tmpCost);
if(active.empty()) cout << ans << endl;
else cout << "-1\n";
}
示例15: replacer
// return path from 0,0 to (N-1, N-1)
vector<pair<int,int> > Dijkstra(multiset<Node, NodeCompare>& nodes, int N)
{
vector<pair<int,int> > the_path; //
multiset<Node,NodeCompare>::iterator best = nodes.begin();
while (!nodes.empty())
{
multiset<Node,NodeCompare>::iterator best = nodes.begin();
if (best->x == N-1 && best->y == N-1)
{
the_path = best->path;
the_path.push_back(pair<int,int>(N-1, N-1));
return the_path;
}
int x = best->x;
int y = best->y;
double curr_cost = best->cost;
vector<pair<int,int> > curr_path = best->path;
nodes.erase(best);
//modify neighboring nodes
for (int i = -2; i <= 2; ++i)
{
for (int j = -2; j <= 2; ++j)
{
if (i == 0 && j == 0 ) { continue;}
multiset<Node,NodeCompare>::iterator next = FindNode(nodes, x + i, y + j);
if (next != nodes.end())
{
if (next->cost > curr_cost + sqrt(i*i + j*j)*next->weight) // update node based on a contrived measure of 'distance'
{
Node replacer(next->x, next->y, curr_cost + sqrt(i*i + j*j)*next->weight, next->weight);
replacer.path = curr_path;
replacer.path.push_back(pair<int,int>(next->x, next->y));
nodes.erase(next);
nodes.insert(replacer);
}
}
}
}
}
return the_path;
}