本文整理汇总了C++中vector::PB方法的典型用法代码示例。如果您正苦于以下问题:C++ vector::PB方法的具体用法?C++ vector::PB怎么用?C++ vector::PB使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vector
的用法示例。
在下文中一共展示了vector::PB方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: solve
void solve(){
for( int i = 0 ; i < n ; i ++ )
if( c[ i ] == '<' ){
if( c[ i + 1 ] == '/' ){
if( c[ i + 2 ] == 'U' ) i += 4;
else i += 6;
v.pop_back();
}else if( c[ i + 1 ] == 'U' ) v.PB( 1 ) , i += 3;
else v.PB( 2 ) , i += 5;
}else{
if( v.size() && v.back() == 1 ) putchar( toC( c[ i ] ) );
else if( v.size() && v.back() == 2 ) putchar( toS( c[ i ] ) );
else putchar( c[ i ] );
}
puts( "" );
}
示例2: main
int main() {
while (~scanf("%d", &n)) {
map<int, int> idx;
ed.clear();
int m = 0;
for (int i = 0; i < n; i++) {
int a, b, r, p;
scanf("%d%d%d%d", &a, &b, &r, &p);
if (idx.find(a) == idx.end()) {
idx[a] = ++m;
}
if (idx.find(b) == idx.end()) {
idx[b] = ++m;
}
ed.PB(Edge(idx[a], idx[b], r, p, i + 1));
}
sort(ed.begin(), ed.end());
for (int i = 1; i <= m; i++) fa[i] = i;
LL res = 0;
for (int i = 0; i < n; i++) {
int pa = find(ed[i].a), pb = find(ed[i].b);
if (pa != pb) {
res += ed[i].p;
fa[pa] = pb;
}
}
cout << res << endl;
for (int i = ed.size() - 1; i >= 0; i--) {
printf("%d%c", ed[i].id, i == 0 ? '\n' : ' ');
}
}
return 0;
}
示例3: dp
void dp(){
int i,j,k;
for(i=0;i<cnt;i++)
for(j=0;j<=n/2;j++)
knap[i][j].tf=0;
knap[0][0].tf=1;
knap[0][0].pre=0;
for(i=1;i<cnt;i++){
for(j=n/2;j>=0;j--){
for(k=0;k<2;k++)
if(j>=L[i].bg[k].size()&&knap[i-1][j-L[i].bg[k].size()].tf){
knap[i][j].tf=1;
knap[i][j].pre=j-L[i].bg[k].size();
knap[i][j].op=k;
}
}
}
int now;
for(i=n/2;i>=0;i--)
if(knap[cnt-1][i].tf){
now=i;
break;
}
for(i=cnt-1;i>=0;i--){
int OP=knap[i][now].op;
for(j=0;j<L[i].bg[OP].size();j++)
A.PB(L[i].bg[OP][j]);
now=knap[i][now].pre;
}
}
示例4: calc
void calc()
{
pll pos = {0, 0};
ll R = 2000000;
while(R > 0)
{
// cout<<"R = "<<R<<" @ "<<pos<<endl;
if(R > 3)
R = ceill(sqrtl(R * R / 2.l));
else
R--;
ll dR = max(R, 1LL);
// cout<<"dR "<<dR<<endl;
for(int i=0; i<4; i++)
{
pll newpos = trim(pos + dir[i] * dR);
int res = query(newpos, R);
// cout<<pos<<" -> "<<newpos<<" : "<<res<<endl;
if(res > 0)
{
pos = newpos;
break;
}
}
}
assert(query(pos, 0) > 0);
vfound.PB(pos);
}
示例5: traverse
void traverse(int i,map<int,int >vec,map<int,bool>row,map<int,bool>col)
{
if(vec.size()==8)
{
bool bt = true;
for(int i =0; i<mymap.size(); i++)
{
if(mymap[i]==vec)
bt =false;
}
if(bt)
mymap.PB(vec);
}
else
{
if(i+1>7)
i =0;
else
i++;
for(int j =0; j<8; j++)
{
if(row.find(i) ==row.end() && col.find(j) ==col.end() && check(vec,i,j))
{
map<int,int>temp = vec;
map<int,bool>t =row;
map<int,bool>f= col;
t[i] =true;
f[j] = true;
temp[j] =i;
traverse(i,temp,t,f);
}
}
}
}
示例6: main
int main(){
ios_base::sync_with_stdio(false);
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> c[i];
Min = min(Min, c[i]);
}
while(m--){
int fi, se;
cin >> fi >> se;
if(c[fi] != c[se])
e.PB(MP(min(c[fi], c[se]), max(c[fi], c[se])));
}
sort(e.begin(), e.end());
e.resize(unique(e.begin(), e.end()) - e.begin());
for(int i = 0; i < e.size(); i++)
a[e[i].L]++, a[e[i].R]++;
int Max = -1, ans;
for(int i = 1; i <= 1e5; i++)
if(a[i] > Max)
Max = a[i], ans = i;
if(Max == 0)
cout << Min << endl;
else
cout << ans << endl;
return 0;
}
示例7: main
int main()
{
int g;
scanf("%d", &g);
for(int i=0; i<g; i++)
{
int a,b;
scanf("%d %d", &a, &b);
v.PB(MP(a,b));
}
int m;
scanf("%d", &m);
for(int i=0; i<m; i++)
{
int x,y,r;
scanf("%d %d %d", &x, &y, &r);
for(int xx=max(0,x-r); xx<min(MX,x+r+1); xx++)
{
for(int yy=max(0,y-r); yy<min(MX,y+r+1); yy++)
{
if((xx-x)*(xx-x) + (yy-y)*(yy-y) <= r*r)
A[xx][yy]=true;
}
}
}
int ans=0;
for(int i=0; i<v.size(); i++)
{
if(!A[v[i].F][v[i].S])
ans++;
}
printf("%d\n", ans);
return 0;
}
示例8: main
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
memset(v, -1, sizeof v);
memset(vc, -1, sizeof vc);
cin >> n >> m;
while(m--){
int fi, se, th;
cin >> fi >> se >> th;
v[fi] = th;
vc[se] = fi;
}
for(int i = 1; i <= n; i++){
if(v[i] != -1)
continue;
int zarf = 1e9;
int x = i;
while(vc[x] != -1){
x = vc[x];
zarf = min(zarf, v[x]);
}
if(x != i)
ans.PB(MP(MP(x, i), zarf));
}
sort(ans.begin(), ans.end());
cout << ans.size() << '\n';
for(auto x : ans)
cout << x.L.L << ' ' << x.L.R << ' ' << x.R << '\n';
return 0;
}
示例9: recurse
void recurse(int val[8],bool arr[8],int t)
{
if(t==8)
{
vector<int>x(8);
for(int i =0;i<8;i++)
x[i ] =val[i];
if(search(x))
{
//cout<<endl;
mymap.PB(x);
}
}
else
{
for(int j =0;j<8;j++)
{
if(arr[j] == false && check(val,t,j))
{
val[t] = j;
arr[j] =true;
recurse(val,arr,t+1);
arr[j] = false;
}
}
}
}
示例10: main
int main()
{
//freopen("test.in", "r", stdin);
scanf("%d", &n);
if(n == 2) { puts("2"); return 0; }
for(int i = 0; i < n; i++)
scanf("%d", &a[i]);
for(int i = 0; i < n; i++)
s.PB(a[i]);
sort(s.BG, s.ED);
int size = unique(s.BG, s.ED) - s.BG;
for(int i = size; i < s.SZ; i++)
s.erase(s.BG + i);
for(int i = 0; i < s.SZ; i++)
f[i].clear();
for(int i = 0; i < n; i++)
f[lower_bound(s.BG, s.BG + size, a[i]) - s.BG].PB(i);
for(int i = 0; i < size; i++) ans = max(ans, (int)f[i].SZ);
for(int i = 0; i < size; i++)
for(int j = 0; j < size; j++)
if(i != j)
{
ans = max(ans, cal(f[i], f[j]));
}
cout << ans << endl;
}
示例11: bfs
int bfs(bool visited[], queue<int> &que, int r, int c, int graph[]){
int temp;
int count = 0;
int flag = 0;
queue <int > output;
int n = r * c;
visited[que.front()] = 1;
while(!que.empty()){
temp = que.front();
if(temp == n-1) flag = 1;
//cout << "Front: " << temp << endl;
if (temp % c && !visited[temp -1]){
visited[temp - 1] = 1;que.push(temp - 1);
}
if(temp % c != c-1 && !visited[temp + 1]){
visited[temp + 1] = 1;que.push(temp + 1);
}
if (temp / c && !visited[temp - c]){
visited[temp - c] = 1;que.push(temp - c);
}
if(temp / c != r-1 && !visited[temp + c]){
visited[temp + c] = 1;que.push(temp + c);
}
que.pop();
// output.push(temp);
count ++;
}
if(flag) mark = count;
else conn_components.PB(count);
return flag;
}
示例12: main
int main(int argc, char const *argv[])
{
int Test;
scanf("%d", &Test);
while (Test--) {
store.clear();
E = 0;
memset(last, -1, sizeof(last));
scanf("%d%d", &n, &m);
//for (int i = 0; i < n; i++) adj[i].clear();
for (int i = 0; i < m; i++) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
addEdge(a, b, c);
addEdge(b, a, c);
}
scanf("%d", &s);
for (int i = 0; i < s; i++) {
int x;
scanf("%d", &x);
store.PB(x);
dijkstra(i);
}
dijkstra(s);
solve();
}
return 0;
}
示例13: input
void input(void){
LL inp;
cin >> inp;
while(inp)
num.PB(inp % 10), inp /= 10;
return;
}
示例14: main
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> h >> w >> n;
for(int i = 0; i < n; i++) {
int fi, se;
cin >> fi >> se;
bl.PB(MP(fi, se));
}
sort(bl.begin(), bl.end());
if(bl[0] == MP(1LL, 1LL) or bl.back() == MP(h, w)) {
cout << 0 << endl;
return 0;
}
fact[0] = 1;
revfact[0] = 1;
for(LL i = 1; i < 250000; i++) {
fact[i] = (fact[i - 1] * i) % Mod;
revfact[i] = ((get(fact[i], Mod).L % Mod) + Mod) % Mod;
}
for(int i = bl.size() - 1; i >= 0; i--) {
dp[i] = C(h - bl[i].L + w - bl[i].R, h - bl[i].L);
for(int j = i + 1; j < bl.size(); j++)
dp[i] = (dp[i] - ((C(bl[j].L + bl[j].R - bl[i].L - bl[i].R, bl[j].L - bl[i].L) * dp[j]) % Mod)) % Mod;
if(dp[i] < 0)
dp[i] += Mod;
}
LL ans = C(h + w - 2, h - 1);
for(int i = 0; i < bl.size(); i++)
ans = (ans - ((C(bl[i].L + bl[i].R - 2, bl[i].L - 1) * dp[i]) % Mod)) % Mod;
cout << (ans + Mod) % Mod << endl;
return 0;
}
示例15: main
int main() {
IOS;
cin >> N >> M;
for (int i=0, u, v; i<M; i++) {
cin >> u >> v;
E[v].PB(u);
deg[u]++;
}
set<int> pq;
for (int i=1; i<=N; i++) {
if (!deg[i]) pq.insert(i);
}
while (!pq.empty()) {
int u = *pq.rbegin();
ans.PB(u);
pq.erase(u);
for (auto v : E[u]) {
deg[v]--;
if (!deg[v]) pq.insert(v);
}
}
reverse(ALL(ans));
for (int i=0; i<N; i++) {
cout << ans[i] << " \n"[i==N-1];
}
return 0;
}