本文整理汇总了C++中vi::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ vi::begin方法的具体用法?C++ vi::begin怎么用?C++ vi::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vi
的用法示例。
在下文中一共展示了vi::begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: expand
void expand(int x,vi & V,ll & ans){
ll p = 1; int idx = 0;
while(idx < sz(V)){
int s = V[idx],nxt = 1 << 20;
if(M.find(x - 1) != M.end()) {
auto p = lower_bound(all(M[x - 1]),s);
if(p != M[x - 1].end()) nxt = *p;
}
if(M.find(x + 1) != M.end()) {
auto p = lower_bound(all(M[x + 1]),s);
if(p != M[x + 1].end()) nxt = min(nxt,*p);
}
if(nxt == (1 << 20)){
ans += p * (sz(V) - 1);
return;
}
int nidx = lower_bound(all(V),nxt) - V.begin();
if(nidx == sz(V)) break;
ll y = 0;
if(M.find(x - 1) != M.end()) {
y += lower_bound(all(M[x - 1]),V[nidx]) - V.begin();
y -= lower_bound(all(M[x - 1]),V[idx]) - V.begin();
}
if(M.find(x + 1) != M.end()) {
y += lower_bound(all(M[x + 1]),V[nidx]) - V.begin();
y -= lower_bound(all(M[x + 1]),V[idx]) - V.begin();
}
p *= (nidx -0LL- idx) * p;
idx = nidx;
}
ans += p;
}
示例2: checkConstraints
bool checkConstraints(vi remStrings, int n, vbs A, vi f){
sort(remStrings.begin(), remStrings.end());
vector<vi> strings;
for(int i=0; i<itv.size(); i++){
vi cur = itv[i];
if(binary_search(remStrings.begin(), remStrings.end(), i)){
continue;
}
strings.push_back(cur);
}
for(int i=0; i<A.size(); i++){
if(A[i].size()==1) continue;
set<vi> s;
for(int j=0; j<strings.size(); j++){
vi curV;
for(int k=0; k<n; k++){
if(!A[i][k]) continue;
curV.push_back(strings[j][k]);
}
s.insert(curV);
if(s.size()>f[i]) return false;
}
}
return true;
}
示例3: main
int main(){
scanf("%d%d", &N, &M);
int a;
for(int i = 0; i < N; ++i){
scanf("%d", &a);
cities.push_back(a);
}
for(int i = 0; i < M; ++i){
scanf("%d", &a);
towers.push_back(a);
}
s = 0;
e = INF;
while(s < e){
r = (s+e)/2;
bool covered = true;
for(int i = 0; i < N; i++){
int low = lower_bound(towers.begin(), towers.end(), cities[i]) - towers.begin();
int high = upper_bound(towers.begin(), towers.end(), cities[i]) - towers.begin();
if(towers[low] == cities[i]) continue;
if(low != 0) low--; // the one before cities[i]
if(high == M) high--;
if(abs(towers[low] - cities[i]) <= r || abs(towers[high] - (ll) cities[i]) <= r) continue;
covered = false;
break;
}
if(covered){
e = r;
}else{
s = r+1;
}
}
cout << s << endl;
}
示例4: printGroups
void printGroups(vi & visited)
{
std::sort(visited.begin(), visited.end());
out("visited: ");
for(vi::const_iterator cit = visited.begin(); cit!=visited.end();++cit){
out("%d ",*cit);
}
out("\n");
vi groups;
vi::const_iterator pit = visited.begin();
vi::const_iterator cit = pit+1;
int currcnt = 1;
while(cit != visited.end()) {
if(*cit == *pit) {
currcnt++;
}
else {
groups.push_back(currcnt);
currcnt = 1;
pit = cit;
}
cit++;
}
groups.push_back(currcnt);
std::sort(groups.begin(), groups.end(), std::greater<int>());
int i = 0;
for(vi::const_iterator cit = groups.begin(); cit!=groups.end() && i < 10;++cit, i++){
printf("%d ",*cit);
}
printf("\n");
}
示例5: id
vi id ( vi state ) {
//--- Phase 1: Edge orientations.
if( phase < 2 )
return vi( state.begin() + 20, state.begin() + 32 );
//-- Phase 2: Corner orientations, E slice edges.
if( phase < 3 ){
vi result( state.begin() + 31, state.begin() + 40 );
for( int e=0; e<12; e++ )
result[0] |= (state[e] / 8) << e;
return result;
}
//--- Phase 3: Edge slices M and S, corner tetrads, overall parity.
if( phase < 4 ){
vi result( 3 );
for( int e=0; e<12; e++ )
result[0] |= ((state[e] > 7) ? 2 : (state[e] & 1)) << (2*e);
for( int c=0; c<8; c++ )
result[1] |= ((state[c+12]-12) & 5) << (3*c);
for( int i=12; i<20; i++ )
for( int j=i+1; j<20; j++ )
result[2] ^= state[i] > state[j];
return result;
}
//--- Phase 4: The rest.
return state;
}
示例6: merge
void merge(vi &v,int l, int p, int h)
{
int i,r,j,k=l,m=p-l+1,n=h-p;
vi L(v.begin()+l,v.begin()+p+1),R(v.begin()+p+1,v.begin()+h+1);
for(l=0,r=0;l<m&&r<n;k++){
if(L[l]<R[r]||L[l]==R[r]){
v[k]=L[l];
++l;
}
else{
invcnt+=m-l;
v[k]=R[r];
++r;
}
}
if(l==m&&r!=n){
for(i=r;i<n&&k<h+1;i++,k++)
v[k]=R[i];
}
if(l!=m&&r==n){
for(i=l;i<m&&k<h+1;i++,k++){
v[k]=L[i];
}
}
}
示例7: main
int main()
{
FILE *in = fopen (PROBLEM_NAME".in","r");
FILE *out = fopen (PROBLEM_NAME".out","w");
int k;
fscanf(in, "%d %d ", &n, &k);
for (int i = 0; i < n; ++i) {
used.push_back(false);
tin.push_back(0);
fup.push_back(0);
vi l;
g.push_back(l);
}
for (int i = 0; i < k; ++i) {
int x, y;
fscanf(in, "%d %d ", &x, &y);
g[x-1].push_back(y-1);
g[y-1].push_back(x-1);
}
timer = 0;
dfs(0);
sort(ans.begin(), ans.end());
ans.erase( unique( ans.begin(), ans.end() ), ans.end() );
fprintf(out, "%d\n", (int)ans.size());
for (size_t i = 0; i < ans.size(); ++i) {
fprintf(out, "%d\n", ans[i]+1);
}
fclose(in);
fclose(out);
return 0;
}
示例8: sol
void sol(){
if(s2<s1){
vi t=a;a=b;b=t;
ll x=s1;s1=s2;s2=x;
t=ida;ida=idb;idb=t;
fliped=!fliped;
}
if(a.empty() || b.empty())return ;
if(abs(s1-s2)==0){return ;}
ll diff = abs(s2 - s1);
ll Y = diff;
int x,y;
x=y=0;
// printf("diff = %lld\n",diff);
for (int i = 0; i < a.size(); ++i) {
vi::iterator it = lower_bound(b.begin(), b.end(), diff/2 + a[i]);
int j = it-b.begin();
if(j && j == b.size())j--;
// printf("i,j=%d,%d\n",i,j);
ll ns1 = s1 - a[i] + b[j];
ll ns2 = s2 - b[j] + a[i];
// printf("debug a[%d] = %d b[%d] = %d\n",i,a[i],j,b[j]);
// printf("debug ns1 = %lld ns2 = %lld\n",ns1,ns2);
if(abs(ns1 - ns2) < Y){
x = i;
y = j;
// printf("debug %d %d\n",x,y);
Y = abs(ns1 - ns2);
}
}
if(Y<diff){
// printf("swaping a[%d] b[%d] diff = %lld\n", x,y, Y);
if(fliped)
ans.push_back(ii(idb[y],ida[x]));
else
ans.push_back(ii(ida[x],idb[y]));
s1 = s1 - a[x] + b[y];
s2 = s2 + a[x] - b[y];
}
// printf("x,y = %d %d\n",x,y);
a.erase(move(a,x));
ida.erase(move(ida,x));
b.erase(move(b,y));
idb.erase(move(idb,y));
}
示例9: forn
forn(i, n) {
int pos = upper_bound(values.begin(), values.end(), param1[i]) - values.begin();
if (typ[i] == 0) {
add(1, 0, list.size(), 0, pos, -1);
} else add(1, 0, list.size(), 0, pos, +1);
int ans = get(1, 0, (int)list.size());
printf("%d\n", ans == -1 ? -1 : list[ans].se);
}
示例10: hapusRadius
void hapusRadius(vi & Lingkaran, int inp){
vi::const_iterator a = Lingkaran.begin();
for (vi::const_iterator i = Lingkaran.begin(); i<Lingkaran.end();++i){
if (*i == inp){
Lingkaran.erase(Lingkaran.begin()+(i-a));
i=Lingkaran.end();
}
}
}
示例11: main
int main()
{
int temp,i;
char c;
cin>>n;
perm.pb(0);
done.pb(0);
for( i=1;i<=n;i++)
{
cin>>temp;
perm.pb(temp);
done.pb(0);
}
for( i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
cin>>c;
if(c=='1')
mat[i][j]=1;
else
mat[i][j]=0;
}
}
for(i=1;i<n;i++)
{
if(done[i]==0)
{
bfs(i);
for(int j=0;j<help.size();j++)
sorted.pb(perm[help[j]]);
sort(help.begin(),help.end());
sort(sorted.begin(),sorted.end());
for(int j=0;j<help.size();j++)
{
perm[help[j]]=sorted[j];
}
help.clear();
sorted.clear();
}
}
for(i=1;i<n;i++)
cout<<perm[i]<<" ";
cout<<perm[i];
return 0;
}
示例12: main
int main() {
// freopen("fence8.in", "r", stdin);
// freopen("fence8.out", "w", stdout);
int i,j,k;
scanf("%d", &n);
boards = vi(n);
for(i=0; i<n; i++) scanf("%d", &boards[i]);
sort(boards.begin(), boards.end());
scanf("%d", &m);
rails = vi(m);
for(i=0; i<m; i++) scanf("%d", &rails[i]);
sort(rails.begin(), rails.end());
cummSum = vi(m);
cummSum[rails.size()-1]=rails[rails.size()-1];
for(int i=rails.size()-2; i>=0; i--){
cummSum[i]=rails[i]+cummSum[i+1];
}
options = vector<vvi>(n);
for(int i=0; i<n; i++){
find_options(i, boards[i], vi(), 0);
//sort options with more rails first
vii p;
for(int j=0; j<options[i].size(); j++){
p.push_back(ii(options[i][j].size(), j));
}
sort(p.rbegin(), p.rend());
vvi newOptions(options[i].size());
for(int j=0; j<p.size(); j++){
newOptions[j]=options[i][p[j].second];
}
options[i]=newOptions;
}
// sort boards with less number of options first
vii p;
for(int i=0; i<n; i++){
p.push_back(ii(options[i].size(), i));
}
sort(p.begin(), p.end());
vector<vvi> newOptions(n);
for(int i=0; i<n; i++){
newOptions[i]=options[p[i].second];
}
options=newOptions;
printf("%d\n", recur(0, bitset<BSM>()));
return 0;
}
示例13: CariRadius
void CariRadius(vi & Lingkaran, int inp){
while(binary_search(Lingkaran.begin(),Lingkaran.end(),inp)){
hapusRadius(Lingkaran,inp);
}
if (!binary_search(Lingkaran.begin(),Lingkaran.end(),inp)){
printf("Tidak ada lingkaran dengan radius %d\n",inp);
}
}
示例14: main
int main() {
int q;
cin >> n >> m >> q;
scanf("%d%d%d", &n, &m, &q);
scanf("%s%s", T, P);
kmpPreprocess(); kmpSearch();
forn(i, q) {
int l, r; cin >> l >> r;
int ind1 = upper_bound(all.begin(), all.end(), l - 2) - all.begin();
int ans = 0;
for(int k = ind1; k < all.size(); k++)
if(all[k] + m <= r) ans++;
printf("%d\n", ans);
}
示例15: getPairs
int getPairs(vi & primes, int n)
{
int count = 0;
vi::iterator jt = std::upper_bound(primes.begin(), primes.end(), n);
//printf("lower bound find %d is %d\n", n, *jt);
for(vi::iterator it = primes.begin(); (*it) <= n && it != jt; it++)
{
int d = n - (*it);
if(std::binary_search(it, jt, d)) {
count++;
//printf("%d + %d = %d\n", *it, n - (*it), n);
}
}
return count;
}