本文整理汇总了C++中multiset::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ multiset::begin方法的具体用法?C++ multiset::begin怎么用?C++ multiset::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiset
的用法示例。
在下文中一共展示了multiset::begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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));
}
}
示例2: MP
pair<int, int> cover() {
multiset<pair<int, int> >::iterator it = milk.begin();
int sum = 1, st = it->first, ed = 0, res1 = 0, res2 = 0;
it++;
for (; it != milk.end(); it++) {
if (it->second == 0) { // left
if (sum == 0) {
res2 = max(res2, it->first - ed);
st = it->first;
}
sum++;
} else if (it->second == 1){ // right
sum--;
if (sum == 0) {
res1 = max(res1, it->first - st);
ed = it->first;
}
}
}
return MP(res1, res2);
}
示例3: main
int main() {
std::ios::sync_with_stdio(false);
while(cin >> n && n) {
sum = 0;
bills.clear();
for(int idx=0; idx<n; ++idx) {
cin >> k;
for(int jdx=0; jdx<k; ++jdx) {
cin >> x;
bills.insert(x);
}
multiset<int>::iterator hit = bills.end(), lot = bills.begin();
hit--;
sum += (*hit)-(*lot);
bills.erase(hit);
bills.erase(lot);
}
cout << sum <<endl;
}
return 0;
}
示例4: main
int main() {
ll t; get(t);
while(t--) {
ll n, k, sum = 0, mx = 0;
get(n); get(k);
v.clear();
rep(n) { ll x; get(x); v.insert(x); sum += x; mx = max(mx,x); }
if( sum%k != 0 )
{ printf("no\n"); continue; }
else if( mx <= sum/k ){
ll val = sum/k, z;
for( z = 1; z <= k; z++ ) {
if( v.empty() )
{ printf("no\n"); break; }
flag = 0;
ll r = *v.rbegin();
r = val - r;
v.erase( v.find(*v.rbegin()) );
rec( v.begin(), v, 0, r );
// cout << r << "---------\n";
if( !flag )
{ printf("no\n"); break; }
}
// cout << " END: " << z << endl;
if( z == k+1 )
printf("yes\n");
}
else {
printf("no\n"); continue;
}
}
}
示例5: main
int main()
{
ifstream in("planificare.in");
ofstream out("planificare.out");
in >> N >> K;
for ( int i = 1; i <= N; ++i )
in >> v[i].x >> v[i].y;
sort(v + 1, v + N + 1);
for ( int i = 1; i <= K; ++i )
MS.insert(0);
for ( int i = 1; i <= N; ++i )
{
auto it = MS.lower_bound(v[i].x);
if ( it != MS.end() && *it == v[i].x )
{
sol++;
MS.erase(it);
MS.insert(v[i].y);
continue;
}
if ( it == MS.begin() )
continue;
it--;
sol++;
MS.erase(it);
MS.insert(v[i].y);
}
out << sol << "\n";
return 0;
}
示例6: main
int main() {
cout.precision(32);
int T; cin >> T;
for(int t = 0; t < T; ++t) {
char op; cin >> op;
int x; cin >> x;
if (op == 'a') {
xs.insert(x);
if (xs.size() == 1) {
pmedian = xs.begin();
} else {
if (x >= *pmedian && (xs.size() % 2 == 1)) {
pmedian++;
}
if (x < *pmedian && (xs.size() % 2 == 0)) {
pmedian--;
}
}
} else {
multiset<int>::iterator px = xs.find(x);
if (px == xs.end()) {
cout << "Wrong!" << endl;
continue;
} else {
xs.erase(px);
}
if (x >= *pmedian && (xs.size() % 2 == 0)) {
pmedian--;
}
if (x < *pmedian && (xs.size() % 2 == 1)) {
pmedian++;
}
}
if (!xs.empty()) cout << median() << endl;
else cout << "Wrong!" << endl;
}
}
示例7: main
int main()
{
int n,k,t,i;
cin>>t;
while(t-- && cin>>n)
{ if(n<10){cout<<n<<endl;continue;}
do
{
k=n;
for(i=9;i>=2;i--)if(n%i==0){n/=i;num.insert(i);}
if(n==k){cout<<"-1";n=-1;break;}
}while(n>=10);
if(n!=-1)
for(it=num.begin();it!=num.end();it++)cout<<*it;
if(n>1)cout<<n;
cout<<endl;
num.clear();
}
return 0;
}
示例8: main
int main()
{
i64 sum = 0;
int n, i, j, p,m;
scanf("%d", &n);
for(i=0; i<n; i++)
{
scanf("%d", &m);
for(j=0; j<m; j++)
{
scanf("%d", &p);
S.insert(p);
}
fwd = S.begin();
rev = S.end();
rev--;
sum += (*rev - *fwd);
S.erase(fwd);
S.erase(rev);
}
printf(FS, sum);
return 0;
}
示例9: main
int main() {
#ifndef ONLINE_JUDGE
freopen("528a.in", "r", stdin);
freopen("528a.out", "w", stdout);
#endif
cin >> w >> h >> n;
rx.insert(0);
rx.insert(w);
ry.insert(0);
ry.insert(h);
distx.insert(-w);
disty.insert(-h);
for(int i = 1 ; i <= n ; ++ i) {
char op; int x;
cin >> op >> x;
if(op == 'V') {
auto p1 = rx.lower_bound(x);
auto p2 = rx.lower_bound(x);
if(p1 != rx.begin())
-- p1;
// cout << "x \n";
// cout << *p1 << ' ' << *p2 << '\n';
rx.insert(x);
distx.erase(distx.find(-(*p2 - *p1)));
distx.insert(-(x - *p1));
distx.insert(-(*p2 - x));
cout << 1LL * (*distx.begin()) * (*disty.begin()) << '\n';
}
else {
auto p1 = ry.lower_bound(x);
auto p2 = ry.lower_bound(x);
if(p1 != ry.begin())
-- p1;
// cout << "y \n";
// cout << *p1 << ' ' << *p2 << '\n';
ry.insert(x);
disty.erase(disty.find(-(*p2 - *p1)));
disty.insert(-(x - *p1));
disty.insert(-(*p2 - x));
cout << 1LL * (*distx.begin()) * (*disty.begin()) << '\n';
}
}
}
示例10: insert
void insert(vec &p){
if(p.x==0) return;
set<vec>::iterator loc=s.insert(p),it1=loc,it2=loc,next;
--it1; ++it2;
if(area(*it1,*it2,p)>0){
s.erase(loc);
return;
}
ans-=dist(*it1,*it2);
for(next=it1;it1!=s.begin();it1=next){
next--;
if(area(*next,*it1,p)>=0) break;
ans-=dist(*next,*it1);
s.erase(it1);
}
ans+=dist(*it1,p);
for(next=it2,next++;next!=s.end();it2=next,next++){
if(area(*next,*it2,p)<=0) break;
ans-=dist(*next,*it2);
s.erase(it2);
}
ans+=dist(*it2,p);
}
示例11: if
main()
{
int n ; scanf("%d",&n) ;
for(int i=1;i<=n;i++) scanf("%d",&h[i]) ;
for(int i=1;i<n;i++)
{
int x,y ; scanf("%d%d",&x,&y) ;
v[x].push_back(y) ;
v[y].push_back(x) ;
}
dfs0(1,-1,h[1]) ;
int k ; scanf("%d",&k) ;
for(int i=1,x;i<=k;i++) scanf("%d",&x) , st.insert(x) ;
for(int i=k+1;i<=n;i++) st.insert(0) ;
for(int i=1;i<=n;i++) cave[i]=(P){i,hm[i]} ;
sort(cave+1,cave+n+1) ;
LIM=-1 ;
for(int i=1;i<=n;i++)
{
auto it=st.upper_bound(cave[i].hm) ;
if(it!=st.begin()) st.erase(--it) ;
else if(LIM==-1) LIM=cave[i].hm ;
}
if(st.empty()) {printf("0\n") ; return 0;}
if(!dfs(1,-1,INF)) {printf("-1\n") ; return 0 ;}
int l=0 , r=INF ;
while(r-l>1)
{
int mid=(r+l)/2 ;
if(dfs(1,-1,mid)) r=mid ;
else l=mid ;
}
printf("%d\n",r) ;
}
示例12: removeNodeFromSet
bool AStar::removeNodeFromSet( multiset<Node>& l,Node n){
n.operationEqual = true;
//printf("Equality check before removing\n");
multiset<Node> ::iterator it;
for(it = l.begin();it!=l.end();it++){
if(n.id == (*it).id){
break;
}
}
#if DEBUG
printf("Trying to remove node %lld\n",n.id);
#endif
if(it==l.end()){
std::cout<<"Shouldn't come here, should be called after ensuring that the element exists in the list\n";
return false;
}
else{
l.erase(it);
return true;
}
}
示例13: if
REP(i, n) {
if (a[i] >= 0) s += a[i];
else if (ps.size() < k) {
s += -a[i];
ps.insert(a[i]);
}else if (k && a[i] < *(--ps.end())) {
int v = *(--ps.end());
ps.erase(--ps.end());
ns.insert(v);
s -= -v, s += v;
r = v;
s += -a[i];
ps.insert(a[i]);
}else { s += a[i];
ns.insert(a[i]);
}
int j = i - l;
if (j >= 0)
if (a[j] >= 0) s -= a[j];
else if (ps.find(a[j])!=ps.end()) {
ps.erase(ps.find(a[j]));
s -= -a[j];
if (!ns.empty()) {
int v = *ns.begin();
ns.erase(ns.begin());
ps.insert(v);
s -= v, s += -v;
}
}else { s -= a[j];
ns.erase(ns.find(a[j]));
}
if (j >= -1) ans = max(ans, s);
}
示例14: main
int main() {
freopen("grass.in", "r", stdin);
freopen("grass.out", "w", stdout);
ios_base::sync_with_stdio(false);
int N, M, K, Q;
cin >> N >> M >> K >> Q;
for (int i = 0; i < M; ++i) cin >> Y[i].a >> Y[i].b >> Y[i].c;
sort(Y, Y + M);
for (int i = 1; i <= N; ++i) {
f[i] = i;
d[i] = 1;
}
int cnt = 0;
for (int i = 0; i < M; ++i) {
if (find(Y[i].a) == find(Y[i].b)) continue;
int a = Y[i].a, b = Y[i].b, c = Y[i].c;
X[a].push_back(make_pair(b, c));
X[b].push_back(make_pair(a, c));
unionn(a, b);
++cnt;
if (cnt == N - 1) break;
}
for (int i = 1; i <= N; ++i) cin >> c[i];
dfs(1, -1);
for (int i = 0; i < Q; ++i) {
int a, b;
cin >> a >> b;
if (c[a] != b) update(a, b);
cout << *S.begin() << endl;
}
return 0;
}
示例15: pairsums
/*****************************************
* Set reconstruction from pairwise sums *
*****************************************
* Given a multiset S of integers, reconstructs
* the multiset V such that S is the multiset of
* pairwise sums of V. Fills in V in sorted order.
* Returns true if successful and false if confused.
* #include <set>
* ACKNOWLEDGEMENTS: Thanks to Stefan Pochmann for
* the idea, David Arthur for the generalized
* algorithm and Bartholomew Furrow for a
* reference implementation.
**/
bool pairsums( int *ans, multiset< int > &seq )
{
int N = seq.size();
if( N < 3 ) return false;
__typeof( seq.end() ) it = seq.begin();
int a = *it++, b = *it++, i = 2;
for( ; i * ( i - 1 ) < 2 * N && it != seq.end(); i++, ++it )
{
// assume seq[i] = ans[1] + ans[2]
ans[0] = a + b - *it;
if( ans[0] & 1 ) continue;
ans[0] >>= 1;
// try ans[0] as a possible least element
multiset< int > seq2 = seq;
int j = 1;
while( seq2.size() )
{
ans[j] = *seq2.begin() - ans[0];
for( int k = 0; k < j; k++ )
{
__typeof( seq2.end() ) jt = seq2.find( ans[k] + ans[j] );
if( jt == seq2.end() ) goto hell;
seq2.erase( jt );
}
j++;
}
hell:;
if( j * ( j - 1 ) < 2 * N ) continue;
// it worked! [modify this to deal with multiple answers]
return true;
}
return false;
}