本文整理汇总了C++中vi::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ vi::clear方法的具体用法?C++ vi::clear怎么用?C++ vi::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vi
的用法示例。
在下文中一共展示了vi::clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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]);
}
示例2: main
int main(){
int t, n, i, c;
scanf("%d", &t);
kase=1;
while(t--){
scanf("%s", str);
n = strlen(str);
grps.clear();
type.clear();
for(i=0; i<n; ){
if(str[i]=='a'){
c=0;
while(i<n && str[i]=='a') c++, i++;
grps.pb(c);
type.pb(0);
}else{
c=0;
while(i<n && str[i]=='b') c++, i++;
grps.pb(c);
type.pb(1);
}
}
done = (1<<grps.size())-1;
printf("%d\n", recur(0));
kase++;
}
return 0;
}
示例3: main
int main() {
int tc;
cin >> tc;
while (tc--) {
int n, m;
cin >> n >> m;
AdjList.clear(); AdjList.resize(n);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
AdjList[a].push_back(ii(b, 0));
}
bool cac = true;
int numScc = 0;
dfs_num.clear(); dfs_num.resize(n, UNVISITED);
dfs_parent.clear(); dfs_parent.resize(n, 0);
for(int i = 0; i < n; i++) {
if(dfs_num[i] == UNVISITED) {
numScc++;
if(graphCheck(i)) {
cac = false;
break;
}
}
}
if(cac && numScc == 1) cout << "YES\n";
else cout << "NO\n";
}
return 0;
}
示例4: main
int main(){
int N, M, a, b, c;
while(cin >> N >> M && N != 0 && M != 0){
AdjList.resize(N);
dfs_num.resize(N);
visited.resize(N);
dfs_low.resize(N);
numSCC = dfsNumberCounter = 0;
for(int i = 0; i < M; i++){
cin >> a >> b >> c;
AdjList[a-1].push_back(b-1);
if(c == 2) AdjList[b-1].push_back(a-1);
}
for(int i = 0; i < N; i++)
if(dfs_num[i] == 0)
tarjan(i);
if(numSCC == 1) cout << 1 << endl;
else cout << 0 << endl;
visited.clear();
AdjList.clear();
dfs_low.clear();
dfs_num.clear();
S.clear();
}
}
示例5: main
int main()
{
p.clear(), sz.clear();
p.assign(33333, 0), sz.assign(33333, 0);
while(1)
{
scanf("%d %d", &n, &m);
if(!n && !m)
break;
initSet(n+1);
num=1;
while(n--)
{
scanf("%s", a);
mp[a]=num++;
}
while(m--)
{
scanf("%s %s", a, b);
Union(mp[a], mp[b]);
}
printf("%d\n", ans);
}
return 0;
}
示例6: main
int main() {
#ifndef ONLINE_JUDGE
freopen("test.inp", "r", stdin);
//freopen("test.out", "w", stdout);
#endif
int cases, caseNo = 0;
for (scanf("%d", &cases); cases--; ) {
scanf("%d %d", &n, &k);
rep(i, n) scanf("%d", &a[i]);
set1.clear(); set2.clear();
buildSet(n / 2 + 1, 0, 0, set1); buildSet(n, n / 2 + 1, 0, set2);
sort(all(set2));
bool ok = false;
for (int i = 0; i < set1.size() && !ok; i++) {
int lo = 0, hi = set2.size() - 1, val = k - set1[i];
while (!ok && lo <= hi) {
int mid = (lo + hi) / 2;
if (set2[mid] == val)
ok = true;
else if (val > set2[mid])
lo = mid + 1;
else hi = mid - 1;
}
}
printf("Case %d: %s\n", ++caseNo, ok ? "Yes" : "No");
}
return 0;
}
示例7: main
int main () {
#ifndef ONLINE_JUDGE
freopen(INP, "r", stdin); freopen(OUT, "w", stdout);
#endif
scanf("%d", &n);
order.clear();
arr1.assign(n+1,0);
a1.clear();
FOR(i,1,n) scanf("%d", &a), a1.pb(a);
REP(i,n) arr1[a1[i]-1] = i+1;
REP(i,n) order[arr1[i]] = i;
while(scanf("%d", &a) != EOF){
arr.assign(n+1,0);
a2.clear();
a2.pb(a);
ans.resize(0);
len = 0;
FOR(i,1,n-1) scanf("%d", &a), a2.pb(a);
REP(i,n) arr[a2[i]-1] = i+1;
REP(i,n) updateLis(arr[i]);
cout << len << endl;
}
return 0;
}
示例8: 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;
}
示例9: 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;
}
示例10: buildUF
void buildUF(int n){
p.clear();
p.assign(n+1,0);
rnk.clear();
for (int i = 0; i <= n; i++) {
p[i]=i;
//members.push_back(1);
rnk.push_back(1);
}
}
示例11: TopologicalSort
bool TopologicalSort(const Graph& g,vi& order)
{
int size=g.size();
order.clear();
vi colors(size);
rep(i,size){
if(!Visit(g,i,colors,order)){
order.clear();
return false;
}
}
reverse(all(order));
return true;
}
示例12: main
int main(){
FASTER;
n = 12;
while(1){
values.clear();
bool end = false;
for (int i = 0,t; i < 12; ++i) {
cin >> t;
values.push_back(t);
end = end || t>0;
}
if(!end)break;
permu.assign(12, 0);
vis.assign(12, 0);
vis[0] = 1;
permu[0] = values[0];
cnt = 0;
go(0);
permu.assign(12, 0);
permu[1] = values[0];
go(0);
cout << cnt/2 << endl;
}
return 0;
}
示例13: main
int main() {
int n, m;
int caso = 0;
while(1) {
edges.clear();
used.clear();
scanf(" %d %d", &n, &m);
for (int i = 1 ; i <= n; i++) maximum_tree[i].clear();
if (!n && !m) break;
used.assign(n+1, 0);
for (int i=0 ; i < m; i++) {
int a, b, c;
scanf(" %d %d %d", &a, &b, &c);
edges.pb(mp(c-1, mp(a,b)));
}
Kruskal(n);
// for (int i = 1; i <= n; i++) {
// cout << i << "-> ";
// for (int j = 0; j < (int) maximum_tree[i].size(); j++) {
// cout << "(" << maximum_tree[i][j].fi << ", " << maximum_tree[i][j].sc << ") ";
// }
// cout << endl;
// }
int from, p;
scanf(" %d %d %d", &from, &go, &p);
double ans = ceil((double) p / (double) dfs(from));
cout << "Scenario #" << ++caso << endl;
cout << "Minimum Number of Trips = " << ans << endl<< endl;
}
}
示例14: main
int main() {
//READ("in.txt");
//WRITE("out.txt");
int t;
getI(t);
for(int ci=1;ci<=t;ci++)
{
v.clear();
SET(dp);
CLR(pri);
getI(totLen);
totLen*=100;
len=0;
int x;
while(getI(x) && x)
{
//x/=100;
v.PB(x);
len++;
}
cout << call(0,0,0) <<endl;
print(0,0,0);
if(ci<t) printf("\n");
}
return 0;
}
示例15: main
int main()
{
vi dist;
int tested;
scanf("%d", &tested);
while(tested--)
{
lista.assign(MAX*MAX, vi());
dist.assign(MAX*MAX, -1);
toposort.clear();
string name;
cin>>name>>row>>column;
int n=0;
for(int i=0;i<row;i++)
for(int j=0;j<column;j++)
scanf("%d", &a[i][j]), b[i][j]=n++;
generate(n);
int ans=-1;
for(int i=0;i<toposort.size();i++)//MAX path
{
int u=toposort[i];
ans=min(ans , dist[u]);
for(int j=0;j<lista[u].size();j++)
{
int v=lista[u][j];
dist[v]=min(dist[v], dist[u] - 1); // update distance
}
}
cout<<name<<": "<<-ans<<endl;
}
}