本文整理汇总了C++中vi::back方法的典型用法代码示例。如果您正苦于以下问题:C++ vi::back方法的具体用法?C++ vi::back怎么用?C++ vi::back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vi
的用法示例。
在下文中一共展示了vi::back方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: find
int TheArray::find (int _n, int _d, int _first, int _last)
{
arr.clear();
d = abs(_d);
n = _n;
first = _first;
last = _last;
if(first > last)
swap(first, last);
arr.pb(first);
while(arr.size() < n){
lft = n - arr.size();
if(arr.back() + 0 - d*(lft-1) <= last)
arr.pb(arr.back() + find1(0, d));
else
arr.pb(max(arr.back()-d, last));
}
/*
tr(it, arr)
write(*it);
cout << endl;
*/
return *max_element(all(arr));
}
示例2: 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();
}
示例3: 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);
}
}
示例4: tarjanSCC
void tarjanSCC(int u)
{
dfs_low[u] = dfs_num[u] = dfsNumberCounter++;
S.push_back(u);
visited[u] = 1;
for (int j = 0; j < (int)AdjList[u].size(); j++)
{
int v = AdjList[u][j];
if (dfs_num[v] == UNVISITED)
tarjanSCC(v);
if (visited[v])
dfs_low[u] = min(dfs_low[u], dfs_low[v]);
}
if (dfs_low[u] == dfs_num[u])
{
int tam = 0;
while (1)
{
++tam;
int v = S.back(); S.pop_back(); visited[v] = 0;
if (u == v) break;
}
if (tam >= 2) ++numSCC;
}
}
示例5: tarjansSCC
/**
* a graph is said to be strongly connected if every vertex is reachable from every other vertex.
*/
void tarjansSCC(int u) {
dfs_num[u] = dfs_lo[u] = dfsNumberCounter++;
S.push_back(u);
visited[u] = true;
for(int i = 0 ; i < g[u].size() ; i++) {
int v = g[u][i];
if(dfs_num[v] == UNVISITED)
tarjansSCC(v);
if(visited[v])
dfs_lo[u] = min(dfs_lo[u], dfs_lo[v]);
}
if(dfs_num[u] == dfs_lo[u]) {
printf("SSC %d:", ++numSCC);
while(1) {
int v = S.back();
S.pop_back();
visited[v] = false;
printf(" %d", v);
if(v == u)break;
}
printf("\n");
}
}
示例6: scc
void scc(int u, int p = -1){
num[u] = lo[u] = cnt++;
vis[u] = 1;
cu.push_back(u);
for(auto v : G[u]){
if(num[v] == -1)
scc(v,u);
if(vis[v])
lo[u] = min(lo[u], lo[v]);
}
if(lo[u]==num[u]){
cc.push_back(vi());
int i = cc.size() - 1;
while(1){
int v = cu.back();
vis[v] = false;
cc[i].push_back(v);
cu.pop_back();
if(u == v)break;
}
}
}
示例7: main
int main(){
ios_base::sync_with_stdio(false);
string linha;
//~ while(getline(cin,linha)){
getline(cin, linha);
//~ cout << linha << endl;
memset(st, 0, sizeof st);
cin >> m;
ans.assign(m, 0);
beg.assign(m, 0);
qs.assign(linha.size(), vi());
int a, b;
for(int i = 0; i < m; i++){
cin >> a >> b;
beg[i] = a-1;
qs[b-1].push_back(i);
}
op.clear();
int q;
for(int i = 0; i < (int)linha.size(); i++){
if(linha[i] == ')'){
if(op.size() > 0){
update(1,0,(int)linha.size()-1, op.back());
op.pop_back();
}
}
for(int j = 0; j < (int)qs[i].size(); j++){
q = qs[i][j];
ans[q] = query(1, 0, (int)linha.size()-1, beg[q], i);
}
if(linha[i] == '(') op.push_back(i);
}
示例8: take
void take() {
int p = pos.back(); pos.pop_back();
for (int pi : pos) {
int d = abs(pi-p);
cnt[d]++;
}
}
示例9: print
void print()
{
printf("%d\n", (int)a.size());
forn(j, (int)a.size() - 1)
printf("%d ", a[j]);
printf("%d\n", a.back());
exit(0);
}
示例10: merge
vi merge(vi vec, int i, int j) {
if (i > j) swap(i, j);
vec[i] += vec[j];
swap(vec[j], vec.back());
vec.pop_back();
sort(ALL(vec));
return vec;
}
示例11: find1
int find1(int l, int r) {
if(l == r)
return l;
int mid = (l+r+1)/2;
if(arr.back() + mid - d*(lft-1) <= last)
return find1(mid, r);
else
return find1(l, mid-1);
}
示例12: solve
void solve() {
arr.clear();
p.clear();
/*
cin >> K >> N;
arr = vi(K);
forn(i, K)
cin >> arr[i];
*/
cin >> N >> K;
int64 b, c, r;
arr = vi(K);
cin >> arr[0] >> b >> c >> r;
forab(i, 1, K-1)
arr[i] = (arr[i-1]*b + c) % r;
forn(i, K)
write(arr[i]);
cout << endl;
sort(all(arr));
uni.pb(arr.front());
p.pb(mp(arr[0], arr[0]));
forn(i, K) {
if(arr[i] != uni.back())
uni.pb(arr[i]);
if(arr[i] == p.back().second)
;
else if(arr[i] == p.back().second+1)
p.back().second++;
else
p.pb(mp(arr[i], arr[i]));
}
forn(i, K)
write(arr[i]);
cout << endl;
forn(i, uni.size())
write(uni[i]);
cout << endl;
tr(it, p)
Pf("(%d, %d) ", it->first, it->second);
cout << endl;
int M = N;
forab(i, K, N) {
N = i;
Pf("arr[%d] = %d\n", N, binarySearch());
}
示例13: main
int main (){
scanf("%d%d", &n, &k);
for (int i = 0; i < n * k / 2; i++){
scanf("%d%d", &x, &y);
a[--x][--y] = a[y][x] = 1;
st[x]++;st[y]++;
if (x > y)swap(x,y);
edge.push_back(make_pair(x,y));
}
for (int i = 0; i < n; i++)
if (st[i]){
euler(i);
for (int j = 1; j < eu.size(); j++)
g[eu[j - 1]].push_back(eu[j]);
if (eu.back() != eu.front())
g[eu.back()].push_back(eu.front());
eu.clear();
}
mt.assign(n, -1);
for (int i = 0; i < n; i++){
u.assign(n, 0);
dfs(i);
}
for (int i = 0; i < n; i++)
ans += mt[i] != -1;
if (ans == n){
puts("YES");
for (int i = 0; i < n; i++){
x = i, y = mt[i];
if (x > y)swap(x,y);
for (int j = 0; j < edge.size(); j++)
if (x == edge[j].first && y == edge[j].second){
printf("%d\n", j + 1);break;}
}
} else puts("NO");
return 0;
}
示例14: tarjanSCC
void tarjanSCC(int u){
dfs_num[u]=dfs_low[u]=dfsC++;
S.push_back(u);
vis[u]=1;
for(int i=0; i<graph[u].size(); i++){
if(dfs_num[graph[u][i]]==-1) tarjanSCC(graph[u][i]);
if(vis[graph[u][i]]) dfs_low[u] = min(dfs_low[u], dfs_low[graph[u][i]]);
}
if(dfs_low[u]==dfs_num[u]){
scc[u]=numSCC;
while(1){
int v = S.back(); S.pop_back();
vis[v]=0;
scc[v]=numSCC;
if(u==v) break;
}
numSCC++;
}
}
示例15: 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] == 0)
tarjanSCC(v.first);
if (visited[v.first])
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
scc.push_back(vi());
while (1) {
int v = S.back(); S.pop_back(); visited[v] = 0;
scc.back().push_back(v);
node_to_scc_num[v] = scc_num;
if (u == v) break; }
scc_num++;
}
}