本文整理汇总了C++中vi::push_back方法的典型用法代码示例。如果您正苦于以下问题:C++ vi::push_back方法的具体用法?C++ vi::push_back怎么用?C++ vi::push_back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vi
的用法示例。
在下文中一共展示了vi::push_back方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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);
}
c = 0;
t = 1;
if(towers[0] > cities[0]){
r = towers[0] - cities[0];
c = 1;
}
while(c<N){
while(cities[c] > towers[t] && t < M) t++;
int d = cities[c] - towers[t-1];
if(t < M) d = min(d, towers[t] - cities[c]);
r = max(r,(ll) d);
c++;
}
cout << r << endl;
}
示例3: bfs
void bfs(int u) {
col[0].clear();
col[1].clear();
queue<int> q;
q.push(u);
vis[u] = 0;
col[0].push_back(u);
while (!q.empty()) {
int u = q.front();
q.pop();
for (int i = 0; i < sz(g[u]); i++) {
int v = g[u][i];
if (vis[v] == -1) {
vis[v] = !vis[u];
q.push(v);
col[vis[v]].push_back(v);
}
}
}
if (sz(col[0]) < sz(col[1])) {
for (int i = 0; i < sz(col[0]); i++)
ans.push_back(col[0][i]);
} else {
for (int i = 0; i < sz(col[1]); i++)
ans.push_back(col[1][i]);
}
}
示例4: main
int main () {
ios_base::sync_with_stdio(0); cin.tie(0);
//cout<<fixed<<setprecision(7); cerr<<fixed<<setprecision(7); //cin.ignore(INT_MAX, ' '); //cout << setfill('0') << setw(5) << 25
int tc = 1, i, j;
for (i=3; i<1100; i++) if (!sieve[i])
for (j=i*i; j<1000100; j+=i+i)
sieve[j] = true;
primes.push_back(2);
for (i=3; i<1000100; i+=2) if (!sieve[i]) primes.push_back(i);
for (i=1; i<primes.size(); i++) difs[primes[i]-primes[i-1]].push_back(ii(primes[i-1], primes[i]));
cin>>tc;
while (tc--) {
cin>>l>>r;
mx = -1; cnt = 0;
for (pair<int, vii> d : difs) {
auto itrl = lower_bound(d.second.begin(), d.second.end(), ii(l, 0), cmp_first);
auto itrr = upper_bound(d.second.begin(), d.second.end(), ii(0, r), cmp_second);
if (itrl == d.second.end() || itrr == d.second.begin()) continue;
itrr--;
int dis = distance(itrl, itrr);
if (dis > mx) {
mx = dis;
cnt = 1;
ans = d.first;
} else if (dis == mx) cnt++;
}
if (cnt != 1) cout<<"No jumping champion"<<endl;
else cout<<"The jumping champion is "<<ans<<endl;
}
return 0;
}
示例5: main
int main(){
// Test
int d, Case =1;
while(scanf("%d", &n) && n){
t.clear();s.clear();
for (int i = 1; i <= n; ++i)
s.push_back(i);
for (int i = 0, tmp; i < n; ++i){
scanf("%d", &tmp);
t.push_back(tmp);
}
printf("Case %d: ",Case++);
if((d = bfs(t,s,2,dist_t,dist_s)) != INF){
printf("%d\n", d);
}else if((d = bfs(s,t,2,dist_s,dist_t)) != INF){
printf("%d\n", d);
}else
printf("5\n");
}
return 0;
}
示例6: main
int main() {
fibo.push_back(0);
int A = 1;
int B = 2;
fibo.push_back(1);
fibo.push_back(2);
int C;
do {
C=A+B;
if(C > MAXVAL) break;
fibo.push_back(C);
A=B;
B=C;
}while(true);
int T;
int X,K;
scanf("%d",&T);
while(T--) {
scanf("%d %d",&X,&K);
printf("%llu\n",part(X,fibo.size()-1,K));
}
return 0;
}
示例7: tarjanSCC
void tarjanSCC(int u) {
dfs_low[u] = dfs_num[u] = dfsNumberCounter++; // dfs_low[u] <= dfs_num[u]
S.push_back(u); // stores u in a vector based on order of visitation
visited[u] = 1;
for (int j = 0; j < (int)AdjList[u].size(); j++) {
ii v = AdjList[u][j];
if (dfs_num[v.first] == DFS_WHITE)
tarjanSCC(v.first);
if (visited[v.first]) // condition for update
dfs_low[u] = min(dfs_low[u], dfs_low[v.first]);
}
if (dfs_low[u] == dfs_num[u]) { // if this is a root (start) of an SCC
int total = 0;
// printf("SCC %d:", ++numSCC); // this part is done after recursion
while (1) {
total++;
int v = S.back(); S.pop_back(); visited[v] = 0;
// printf(" %d", v);
if (u == v){
if(total == 1 && AdjList[u][0].first != u){
valid = false;
}
break;
}
}
// printf(" TOTAL: %d \n", total);
clyces.push_back(total % 2 == 0 ? total/2 : total);
}
}
示例8: compute_hull
void compute_hull() {
int pivot = 0, n = p.size();
vector<int> ps(n + 1, 0);
for (int i = 1; i < n; ++i) {
ps[i] = i;
if (comp_lexo(p[i], p[pivot])) pivot = i;
}
ps[0] = ps[n] = pivot; ps[pivot] = 0;
sort(ps.begin()+1, ps.end()-1, [this, &pivot](int l, int r) {
return comp_angl(p[l], p[r], p[pivot]); });
h.push_back(ps[0]);
size_t i = 1; ll d;
while (i < ps.size()) {
if (p[ps[i]] == p[h.back()]) { i++; continue; }
if (h.size() < 2 || ((d = det(p[h.end()[-2]],
p[h.back()], p[ps[i]])) > 0)) { // >= for col.
h.push_back(ps[i]);
i++; continue;
}
if (p[h.end()[-2]] == p[ps[i]]) { i++; continue; }
h.pop_back();
if (d == 0) h.push_back(ps[i]);
}
if (h.size() > 1 && h.back() == pivot) h.pop_back();
}
示例9: main
int main(){
findprimes();
ll n, res;
cin >> n;
while(n!= 0){
res = n;
if(n < 0){
results.push_back(-1);
res = res/-1;
}
int idx = 0;
while(res != 1){
DEBUG(res);
if(res%primos[idx] == 0){
res = res/primos[idx];
results.push_back(primos[idx]);
}else{
idx++;
}
}
printf("%d = ", n);
REP(i, results.size()-1) printf("%d x ", results[i]);
printf("%d\n", results[results.size()-1]);
cin >> n;
results.clear();
}
}
示例10: reconstruct
void reconstruct(int i, int last, int b){
if(i>=k) return;
int choice=0, level=0;
di cur, maxv(-1, -1);
for(int j=1; j<=n; j++){
if(c[j]<=b && j!=last) {
cur = dp[i+1][j][b-c[j]];
cur.first += v[j];
if(cur.first>maxv.first || fabs(cur.first-maxv.first)<EPS) {
if(fabs(cur.first-maxv.first)<EPS) {
if(cur.second > maxv.second) { maxv=cur; choice=j; level=0; }
}else { maxv=cur; choice=j; level=0; }
}
if(i<k-1 && 2*c[j]<=b){
cur = dp[i+2][j][b-2*c[j]];
cur.first += 1.5*v[j];
if(cur.first>maxv.first || fabs(cur.first-maxv.first)<EPS) {
if(fabs(cur.first-maxv.first)<EPS) {
if(cur.second>maxv.second) { maxv=cur; choice=j; level=1; }
}else { maxv=cur; choice=j; level=1; }
}
}
}
}
ans.push_back(choice);
if(level==0) reconstruct(i+1, choice, b-c[choice]);
else { ans.push_back(choice); reconstruct(i+2, choice, b-2*c[choice]); }
}
示例11: convex_hull
void convex_hull(vector<Point> & a) {
if (a.size() == 1)
return;
sort(a.begin(), a.end(), &cmp);
Point p1 = a[0], p2 = a.back();
vector<Point> up, down;
up1.clear();
down1.clear();
up.push_back(p1); up1.pb(0);
down.push_back(p1); down1.pb(0);
for (size_t i = 1; i < a.size(); ++i) {
if (i == a.size() - 1 || ccw(p1, a[i], p2)) {
while (up.size() >= 2 && !ccw(up[up.size() - 2], up[up.size() - 1], a[i]))
up.pop_back(),up1.pop_back();
up.push_back(a[i]),up1.push_back(i);
}
if (i == a.size() - 1 || cw(p1, a[i], p2)) {
while (down.size() >= 2 && !cw(down[down.size() - 2], down[down.size() - 1], a[i]))
down.pop_back(),down1.pop_back();
down.push_back(a[i]),down1.push_back(i);
}
}
if (up[0].x == up.back().x && up[0].y == up.back().y)
up.erase(up.end() - 1),up1.erase(up1.end()-1);
a.clear();a1.clear();
for (size_t i = 0; i < up.size(); ++i)
a.push_back(up[i]),a1.push_back(up1[i]);
for (size_t i = down.size() - 2; i > 0; --i)
a.push_back(down[i]),a1.push_back(down1[i]);
}
示例12: 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;
}
示例13: eratostenes
void eratostenes(int n, vi &p) {
// Inicializando a lista de candidatos a primos.
vi l;
for (int i = 0; i < n / 2; i++) {
l.push_back(2 * i + 3);
}
// Para cada candidato.
for (int i = 0; i < n / 2; i++) {
// Como cortamos os múltiplos de dois, precisamos mapear os índices.
int c = l[i];
if (c != -1) {
// Como eu só começo a marcar a partir de c * c.
if (c * c > n) {
break;
}
// Começando a cortar a partir do quadrado de l[i] = c.
for (int idx = (c * c - 3) / 2; idx < n / 2; idx += c) {
l[idx] = -1;
}
}
}
// Vendo os primos.
if (n >= 2) p.push_back(2);
for (int i = 0; i < n / 2; i++) if (l[i] != -1) p.push_back(l[i]);
}
示例14:
rep(j,sw){
if(grid[i][j]=='#'){
is.push_back(i);
is.push_back(i+h-sh+1);
js.push_back(j);
js.push_back(j+w-sw+1);
}
}
示例15: main
int main()
{
int n;
int ans=1, count=1, pos=1, ind=1;
while(scanf("%d", &n)!=EOF)
{
v.push_back(n);
indexes.push_back(1);
++count;
}
int seq[count];
seq[1]=v[0];
for(int i=1;i<v.size();++i)
{
if(v[i]<seq[1])
{
seq[1]=v[i];
indexes[i]=1;
}
else
if(v[i]>seq[pos])
{
seq[++pos]=v[i];
indexes[i]=pos;
}
else
{
int place=binary_search_find(seq, pos, v[i]);
seq[place]=v[i];
indexes[i]=place;
}
if(indexes[i]>=ans)
{
ans=indexes[i];
ind=i;
}
}
int p=ans;
for(int i=ind;i>=0 && p>0;i--)
{
if(indexes[i]==p)
{
rev.push_back(v[i]);
--p;
}
}
printf("%d\n-\n", ans);
for(int i=rev.size()-1;i>=0;i--)
{
printf("%d\n", rev[i]);
}
return 0;
}