本文整理汇总了C++中vi::assign方法的典型用法代码示例。如果您正苦于以下问题:C++ vi::assign方法的具体用法?C++ vi::assign怎么用?C++ vi::assign使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vi
的用法示例。
在下文中一共展示了vi::assign方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: st_create
void st_create(vi &st, const vi &a)
{
int size = (int)(2 * pow(2.0, floor((log((double)a.size()) / log(2.0) + 1))));
st.assign(size, 0);
st_build(st, a, 1, 0, (int)a.size() - 1);
}
示例2: main
int main() {
int V, total_neighbors, id, weight;
/*
// Use the following input:
// Graph in Figure 4.1
9
1 1 0
3 0 0 2 0 3 0
2 1 0 3 0
3 1 0 2 0 4 0
1 3 0
0
2 7 0 8 0
1 6 0
1 6 0
// Example of directed acyclic graph in Figure 4.4 (for toposort)
8
2 1 0 2 0
2 2 0 3 0
2 3 0 5 0
1 4 0
0
0
0
1 6 0
// Example of directed graph with back edges
3
1 1 0
1 2 0
1 0 0
// Left graph in Figure 4.6/4.7/4.8
6
1 1 0
3 0 0 2 0 4 0
1 1 0
1 4 0
3 1 0 3 0 5 0
1 4 0
// Right graph in Figure 4.6/4.7/4.8
6
1 1 0
5 0 0 2 0 3 0 4 0 5 0
1 1 0
1 1 0
2 1 0 5 0
2 1 0 4 0
// Directed graph in Figure 4.9
8
1 1 0
1 3 0
1 1 0
2 2 0 4 0
1 5 0
1 7 0
1 4 0
1 6 0
*/
freopen("in_01.txt", "r", stdin);
scanf("%d", &V);
AdjList.assign(V, vii()); // assign blank vectors of pair<int, int>s to AdjList
for (int i = 0; i < V; i++) {
scanf("%d", &total_neighbors);
for (int j = 0; j < total_neighbors; j++) {
scanf("%d %d", &id, &weight);
AdjList[i].push_back(ii(id, weight));
}
}
printThis("Standard DFS Demo (the input graph must be UNDIRECTED)");
numCC = 0;
dfs_num.assign(V, DFS_WHITE); // this sets all vertices' state to DFS_WHITE
for (int i = 0; i < V; i++) // for each vertex i in [0..V-1]
if (dfs_num[i] == DFS_WHITE) // if that vertex is not visited yet
printf("Component %d:", ++numCC), dfs(i), printf("\n"); // 3 lines here!
printf("There are %d connected components\n", numCC);
printThis("Flood Fill Demo (the input graph must be UNDIRECTED)");
numCC = 0;
dfs_num.assign(V, DFS_WHITE);
for (int i = 0; i < V; i++)
if (dfs_num[i] == DFS_WHITE)
floodfill(i, ++numCC);
for (int i = 0; i < V; i++)
printf("Vertex %d has color %d\n", i, dfs_num[i]);
// make sure that the given graph is DAG
printThis("Topological Sort (the input graph must be DAG)");
topoSort.clear();
dfs_num.assign(V, DFS_WHITE);
for (int i = 0; i < V; i++) // this part is the same as finding CCs
if (dfs_num[i] == DFS_WHITE)
dfs2(i);
//.........这里部分代码省略.........
示例3:
SegmentTree(const vector<int> &_A){
A = _A; n = (int)A.size();
st.assign(4 * n, 0);
build(1, 0, n-1);
}
示例4:
SegmentTree(vi &_A){
size = (int)_A.size();
A = _A;
tree.assign(size*4,0);
build(1,0,size-1);
}
示例5: SegmentTree
SegmentTree(const vi &_A){
A = _A; n = (int) A.size();
st.assign(n * 4, 0);
lazy.assign(n * 4, -1);
build(1, 0, n - 1);
}
示例6: main
int main(){
FASTER;
cin >> n >> q;
vi W(3000000,0);
ft.assign(6000000,0);
for (int i = 0; i < n; ++i) {
int t;
cin >> t;
v.push_back(t);
W[t]++;
if(query(t,t) == 0){
update(t,1);
}
}
st1.assign(20000000,0);
st2.assign(20000000,0);
buildMax(1,0,v.size()-1);
buildMin(1,0,v.size()-1);
for (int i = 0; i < q; ++i) {
char c;
int x,y;
cin >> c >>x >> y;
if(c == 'Q'){
y--;
int maxi = queryMax(1,0,v.size()-1, x,y);
int mini = queryMin(1,0,v.size()-1, x,y);
printf("range (%d,%d) = %lld %lld\n",mini,maxi, v[mini], v[maxi]);
ll cnt = query(v[mini],v[maxi]);
cout << cnt << endl;
}else{
ll val = v[x];
if(W[val]){
printf("remove %lld\n", val);
W[val]--;
if(W[val] == 0 && query(val,val) == 1){
update(val,-1);
}
}
W[y]++;
if(query(y,y) == 0){
update(y,1);
}
updateMax(1,x,0,(int)v.size()-1,y);
updateMin(1,x,0,(int)v.size()-1,y);
}
}
return 0;
}
示例7: main
int main(){
FASTER;
int n,m;
while(cin >> n >> m, n || m){
A.assign(n+1,0);
for (int i = 1; i <= n; ++i) {
cin >> A[i];
}
int s = 0;
MEM(C,0);
// pre-compute
for (int i = 1; i <= n; ++i) {
s = A[i];
for (int j = i+1; j <= n; ++j) {
C[i][j] = s * A[j] + C[i][j-1];
s += A[j];
}
}
if(m == 0){
cout << C[1][n] << endl;
continue;
}
MEM(dp,0);
for (int i = 0; i <= n; ++i)
for (int j = 0; j <= m+1; ++j)
dp[i][j] = 1e9;
// Slow
// dp[0][0] = 0;
// for (int i = 1; i <= n; ++i) {
// for (int j = 1; j <= i; ++j) {
// for (int k = 1; k <= i; ++ k) {
// int tmp = dp[k-1][j-1] + C[k][i];
// dp[i][j] = min(dp[i][j], tmp);
// }
// }
// }
// cout << dp[n][m+1] << endl;
// Fast
dp[n+1][0] = 0;
for (int i = n; i >= 1; --i) {
for (int j = 1; j <= n; ++j) {
for (int k = i; k <= n; ++k) {
int tmp = dp[k+1][j-1] + C[i][k];
// optimization
if(C[i][k] > dp[i][j] )break;
dp[i][j] = min(dp[i][j], tmp);
}
}
}
cout << dp[1][m+1] << endl;
}
return 0;
}