本文整理汇总了C++中vii类的典型用法代码示例。如果您正苦于以下问题:C++ vii类的具体用法?C++ vii怎么用?C++ vii使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了vii类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: goto_free_point
int goto_free_point(const vii& g, int& t){
vi bfs;
vi res;
vi revisited;
revisited.resize(num_intersect);
for(int i=0; i < num_intersect; ++i)
revisited[i] = 0;
for(int i=0; i < (int)g.size(); ++i)
bfs.push_back(g[i].first);
int go;
while(!bfs.empty()){
go = bfs.back();
bfs.pop_back();
if(visited[go] && !revisited[go]){
res.push_back(go);
revisited[go] = 1;
for(int i=0; i < (int)g.size(); ++i)
if(!revisited[go])
bfs.push_back(graph[go][i].first);
}
else{
break;
}
}
for(int i=0; i < (int)res.size(); ++i)
vpath[veh].push_back(res[i]);
return go;
}
示例2: out
void out(const vii & x, int b, int e) {
if (b >= e || x[b].first == x[e - 1].first)
return;
int mid = x[(b + e) / 2].first;
int i = b;
for (; i < x.size() && x[i].first < mid; ++i)
res.push_back(pii(mid, x[i].second));
out(x, b, i);
for (i = e - 1; i >= b && x[i].first > mid; --i)
res.push_back(pii(mid, x[i].second));
out(x, i + 1, e);
}
示例3: main
int main(){
FASTER;
vii temp;
cin >> n;
s1=s2=0;
for (int i = 0,t; i < n; ++i) {
cin >> t;
temp.push_back(ii(t,i));
}
sort(temp.begin(),temp.end());
for (int i = 0; i <n; ++i) {
a.push_back(temp[i].first);
ida.push_back(temp[i].second+1);
}
temp.clear();
cin >> m;
for (int i = 0,t; i <m; ++i) {
cin >> t;
temp.push_back(ii(t,i));
}
sort(temp.begin(),temp.end());
for (int i = 0; i < m; ++i) {
b.push_back(temp[i].first);
idb.push_back(temp[i].second+1);
}
temp.clear();
s1=s2=0;
for (int i = 0; i < a.size(); ++i) {
s1+=a[i];
}
for (int i = 0; i < b.size(); ++i) {
s2+=b[i];
}
sol();sol();
// printf("%lld %lld\n",s1,s2);
cout << abs(s1-s2) << endl;
cout << ans.size() << endl;
if(ans.size()){
for (int i = 0; i < ans.size(); ++i) {
cout << ans[i].first << " " << ans[i].second << endl;
}
}
return 0;
}
示例4: primeFactors
void primeFactors(ll N, vii &factors) {
ll PF_idx = 0, PF = primes[PF_idx];
while (PF * PF <= N){
ii f(PF, 0);
while (N % PF == 0){
N /= PF;
f.second++;
}
if (f.second > 0){
factors.push_back(f);
}
PF = primes[++PF_idx];
}
if (N != 1) factors.push_back(ii(N,1));
}
示例5: get_road
int get_road(int ridx, const vii& g, int &t){
coord_t dir = directions[ridx];
double min_dist = 800000000.0;
int res = -1;
for(int i = 0; i < (int)g.size(); ++i){
double min_dist2= dist(dir, coords[g[i].first]);
if(visited[g[i].first] < 2 && min_dist > min_dist2){
min_dist = min_dist2;
res = i;
}
}
// if(res == -1) return goto_free_point(g, t);
// return res;
return (res == -1)?droad(rd)%g.size():res;
}
示例6: ok
bool ok(int l){
int c1 = 0;
int c2 = 0;
for (int i = 1; i <= l; ++i) {
if(a[i] < a[c1])c1 = i;
if(b[i] < b[c2])c2 = i;
}
vector<pair<ll, ii> > p;
for (int i = 0; i < m; ++i) {
if(tp[i]==1) p.push_back(pair<ll, ii> (a[c1]*c[i], ii(i,c1)));
if(tp[i]==2) p.push_back(pair<ll, ii> (b[c2]*c[i], ii(i,c2)));
}
sort(p.begin(), p.end());
int sum = 0;
int cnt = 0;
X.clear();
for (int i = 0; i < p.size(); ++i) {
if(sum+p[i].first>s)break;
sum+=p[i].first;
X.push_back(p[i].second);
cnt++;
}
return cnt >= k;
}
示例7: main
int main() {
ios::sync_with_stdio(0);
double d;
int m, tc = 1;
while( cin >> d >> m) {
cout << "Case " << tc++ << ":" << endl;
memo.clear(); memo.resize(105, -1);
prices.clear(); prices.resize(m + 1);
prices[0].first = 1; prices[0].second = (d + eps) * 100;
for(int i = 1; i <= m; i++) {
int tmp; cin >> tmp >> d;
prices[i].first = tmp; prices[i].second = (d + eps) * 100;
}
string str;
cin.get();
getline(cin, str);
stringstream ss(str);
int tmp;
while(ss >> tmp) {
cout << "Buy " << tmp << " for $" << fixed << setprecision(2) << (double)solve(tmp) / 100 << endl;
}
}
return 0;
}
示例8: main
int main(){
int vertices,arestas,caso=1;
while(scanf("%d %d", &vertices, &arestas) && vertices && arestas){
for(int i = 0; i < arestas; i++)
{
int u,v;
scanf("%d %d", &u, &v);
adj[u].push_back(v);
adj[v].push_back(u);
}
memset(dfs_num, -1 , sizeof(dfs_num));
memset(visitados, 0 , sizeof(visitados));
dfsNumbercounter = 0;
for(int i = 0; i <= vertices; i++){
if(dfs_num[i]==DFS_WHITE){findBridges(i);}
}
cout << caso++ << endl;
cout << endl;
for(int i = 0; i < bridge.size();i++){
printf("%d %d\n",bridge[i].first,bridge[i].second);
}
cout << "#" << endl;
bridge.clear();
int i=vertices+5;
while(i--){
adj[i].clear();
}
}
return 0;
}
示例9: main
int main(){
FASTER;
int n;
int Case=1;
while(cin >> n, n){
cas.clear();
for(int i = 0 ; i < n ; i++){
int a,m,g;
cin >> a >> m >> g;
castle c{a,m,g};
C.push_back(c);
cas.push_back(ii(max(a,m+g), m+g));
}
adj.assign(n,vi());
for(int i = 0 ; i < n-1;i++){
int u,v;cin >> u >> v;
u--,v--;
adj[u].push_back(v);
adj[v].push_back(u);
}
ii ans = ii(1e9,1e9);
for(int i = 0 ; i < 1;i++){
ans = min(ans,dfs(i));
}
cout << "Case " << (Case++)<< ": ";
cout << ans.first << endl;
}
}
示例10: main
int main()
{
ifstream fin("marathon.in");
ofstream fout("marathon.out");
int N;
fin >> N;
points.resize(N);
for (int i = 0; i < N; ++i)
{
fin >> points[i].first >> points[i].second;
}
T.resize(N - 2);
res.resize(N - 2);
T[0].first = 0;
T[0].second = dist_cont(2, N-1);
res[0] = T[0].first + T[0].second + dist_two(0, 2);
int result = res[0];
for (int k = 1; k <= N - 3; ++k)
{
T[k].first = T[k - 1].first + dist_two(k - 1, k);
T[k].second = T[k - 1].second - dist_two(k + 1, k+2);
res[k] = T[k].first + T[k].second + dist_two(k, k + 2);
result = min(result, res[k]);
}
fout << result << '\n';
return 0;
}
示例11: doGreedy
void doGreedy()
{
int cek;
LL total = 0;
// SOrt dlu
sort(dragons.begin(), dragons.end());
sort(knights.begin(), knights.end());
REP(a,n)
{
cek = 0;
REP(b,m)
{
//printf("dragon : %d \n",dragons[a]);
// Ga bisa dipake lagi
if(knights[b].second == 1) continue;
if(knights[b].first >= dragons[a] )
{
//printf("KILL by : %d\n",knights[b].first);
cek = 1;
total += knights[b].first;
knights[b].second = 1;
break;
}
}
if(!cek)
{
break;
}
}
示例12: main
int main() {
freopen("milk.in", "r", stdin);
freopen("milk.out", "w", stdout);
int n, m, i,j, a,b;
long long p;
scanf("%d %d", &n, &m);
for(i=0; i<m; i++) scanf("%d %d", &a, &b), farmers.push_back(ii(a,b));
sort(farmers.begin(), farmers.end());
p=0;
for(i=0; n>0; i++){
if(n>=farmers[i].second){
n-=farmers[i].second;
p+=farmers[i].first*farmers[i].second;
}else{
p+=farmers[i].first*n;
n=0;
}
}
printf("%lld\n", p);
return 0;
}
示例13: main
int main(){
FILE *f;
f =fopen("input/OrderingTasks.in", "r");
#ifdef ONLINE_JUDGE
f = stdin;
#endif
int m,n;
while(fscanf(f, "%d %d", &n, &m) == 2 && n){
g.clear();
g.assign(n, vi());
for(int i = 0 ; i < m ; i++){
int u,v;
fscanf(f, "%d %d", &u,&v);
g[u-1].push_back(v-1);
}
vi sortedV;
for(int i = 0 ; i < n ; i++){
if(!visited[i])
dfs(i, sortedV);
}
memset(visited, 0, sizeof visited);
for(int i = sortedV.size() -1 ; i >= 0 ; i--){
printf("%d", sortedV[i] + 1);
if(i)printf(" ");
else printf("\n");
}
}
return 0;
}
示例14: main
int main() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
scanf("%d", &n);
ll sum = 0;
for(int i = 0; i < n; ++i) {
int a, b; scanf("%d %d", &a, &b);
sum += a;
s.pb(mp(a, -1));
s.pb(mp(b, 1));
}
sort(s.begin(), s.end());
ll qtd = 0;
ll maxi = sum;
ll p = 0;
for(int i = 0; i < s.size(); ++i) {
if(s[i].S == -1) {
qtd -= s[i].S;
sum -= s[i].F;
}
ll foo = qtd * (ll)s[i].F + sum;
if(foo > maxi) {
maxi = foo;
p = s[i].F;
}
if(s[i].S == 1) qtd -= s[i].S;
}
printf("%lld %lld\n", p, maxi);
return 0;
}
示例15: findBridges
void findBridges(int u)
{
dfs_num[u]=dfs_low[u]=dfsNumbercounter++;
for(int i =0; i < adj[u].size();i++){
int vizinho = adj[u][i];
if(dfs_num[vizinho] == DFS_WHITE)
{
dfs_parent[vizinho] = u;
findBridges(vizinho);
if(dfs_low[vizinho]>dfs_num[u]){
bridge.push_back(ii(u,vizinho));
bridge.push_back(ii(vizinho,u));
}
else {bridge.push_back(ii(u,vizinho));}
visitados[u][vizinho]=visitados[vizinho][u]=true;
dfs_low[u]=min(dfs_low[u],dfs_low[vizinho]);
}
else if(vizinho!=dfs_parent[u]){
dfs_low[u] = min(dfs_low[u],dfs_num[vizinho]);
if(!visitados[u][vizinho]){
bridge.push_back(ii(u,vizinho));
visitados[u][vizinho]=visitados[vizinho][u]=true;
}
}
}
}