本文整理汇总了C++中vii::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ vii::begin方法的具体用法?C++ vii::begin怎么用?C++ vii::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vii
的用法示例。
在下文中一共展示了vii::begin方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(){
int t,m,u,v,w;
scanf("%d",&t);
while(t--){
sum=1;
edges.clear();
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
pSet[i]=i;
}
for (int i = 0; i < m; ++i)
{
scanf("%d%d%d",&u,&v,&w);
edges.push_back(make_pair(u, make_pair(v,w)));
}
sort(edges.begin(),edges.end(),compare);
for (vector< pair<int,ii> >::iterator i = edges.begin(); i != edges.end(); ++i)
{
// printf("%d %d %d\n", i->first,i->second.first,i->second.second);
if(!isSameSet(i->first,i->second.first)){
sum*=(i->second.second);
if(sum>mod)
sum=sum%mod;
unionSet(i->first,i->second.first);
}
}
printf("%lld\n",sum%mod);
}
return 0;
}
示例2: main
int main(){
int n, i, k, a,b, maxlis;
scanf("%d", &n);
for(i=0; i<n; i++) {
scanf("%d %d", &a, &b);
pairs.push_back(make_pair(a,b));
}
vii::iterator low;
lis.push_back(pairs[0]);
for(i=1, k=1, maxlis=1; i<n; i++){
if(pairs[i].first>lis[k].first && pairs[i].second>lis[k].second) {
if(k+1==lis.size())
lis.push_back(pairs[i]);
else
lis[++k]=pairs[i];
if(k+1>maxlis) maxlis=k+1;
} else{
low = lower_bound(lis.begin(), lis.begin()+k+1, pairs[i]);
lis[k=low-lis.begin()]=pairs[i];
}
}
printf("%d\n", maxlis);
return 0;
}
示例3: 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;
}
示例4: 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;
}
}
示例5: 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;
}
示例6: main
int main() {
int n;
cin >> n;
vector<pii> x(n);
for (int i = 0; i < n; ++i) {
cin >> x[i].first >> x[i].second;
}
sort(x.begin(), x.end());
res = x;
out(x, 0, x.size());
/* for (int i = 0; i < res.size(); ++i)
swap(res[i].first, res[i].second);
res = out(res);
for (int i = 0; i < res.size(); ++i)
swap(res[i].first, res[i].second);
res.push_back(pii(-1e9 - 10, 0));
res = out(res);*/
sort(res.begin(), res.end());
res.resize(unique(res.begin(), res.end()) - res.begin());
cout << res.size() << endl;
for (int i = 0; i < res.size(); ++i)
cout << res[i].first << " " << res[i].second << endl;
return 0;
}
示例7: main
int main() {
int n,x,c;
scanf("%d", &n);
for(int i=0; i<n; i++){
scanf("%d %d", &x, &c);
m.pb(ii(x,c));
}
sort(m.begin(), m.end());
memset(dp, -1, sizeof dp);
printf("%d\n", m[0].second+recur(1,0));
return 0;
}
示例8: main
int main(){
int t, n, i,j, x,y;
scanf("%d", &t);
while(t--){
scanf("%d", &n);
ps.clear();
for(i=0; i<n; i++){ scanf("%d", &x); ps.push_back(ii(x,-1)); }
for(i=0; i<n; i++){ scanf("%d", &x); ps[i].second=x; }
sort(ps.begin(), ps.end());
ys.clear();
for(i=0; i<n; i++) ys.push_back(ps[i].second);
printf("%d\n", LIS_Len(ys));
}
return 0;
}
示例9: main
int main() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
scanf("%d %d", &k, &n);
for(int i = 0; i < n; ++i) {
scanf("%d", c + i);
foo.pb(mp(c[i], i));
}
sort(foo.begin(), foo.end());
for(int i = 0; i < n; ++i) {
int id = foo[i].S, x = foo[i].F;
int mini = min(x, k);
k -= mini;
sol[id] = mini;
}
for(int i = 0 ; i < n; ++i) {
if(i) printf(" ");
printf("%d", sol[i]);
}
printf("\n");
return 0;
}
示例10: main
int main() {
int n, m, u,v,w;
scanf("%d %d", &n, &m);
for(int i=0; i<m; i++){
scanf("%d %d %d", &u, &v, &w);
l.push_back(ii(w, u));
graph[u-1].push_back(ii(v-1,w));
}
for(int i=0; i<n; i++) cnts[i]=vi(graph[i].size(), -1), sort(graph[i].begin(), graph[i].end(), ii_comp());
memset(vis, 0, sizeof vis);
sort(l.begin(), l.end());
int maxv=0;
for(int i=0; i<l.size(); i++) if(vis[l[i].second]==0) maxv = max(maxv, dfs(l[i].second, 0));
printf("%d\n", maxv);
return 0;
}
示例11: main
int main() {
freopen("milk2.in", "r", stdin);
freopen("milk2.out", "w", stdout);
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
int x, y;
cin >> x >> y;
t.push_back(pii(x, y));
}
sort(t.begin(), t.end());
int ans1=0, ans2=0;
int start = t[0].first;
int end = t[0].second;
ans1 = end - start;
for (int i = 1; i < n; i++)
{
if (t[i].first <= end) {
end = max(end, t[i].second);
}
else{
ans2 = max(t[i].first - end, ans2);
start = t[i].first;
end = t[i].second;
}
ans1 = max(end - start, ans1);
}
cout << ans1 << " " << ans2 << endl;
return 0;
}
示例12: main
int main(){
ios::sync_with_stdio(0);
int n;
while(cin >> n) {
int a, num, b;
char c;
cont = 0;
dfs_num.clear();
dfs_num.resize(n, -1);
dfs_low.clear();
dfs_low.resize(n);
dfs_parent.clear();
dfs_parent.resize(n);
vec.clear();
vec.resize(n);
for (int i = 0; i < n; ++i) {
cin >> a >> c >> num >> c;
for (int j = 0; j < num; ++j) {
cin >> b;
vec[a].push_back(b);
}
}
for (int k = 0; k < n; ++k)
if (dfs_num[k] == -1)
artiBri(k);
sort(bri.begin(), bri.end());
cout << bri.size() << " critical links" << endl;
for (int l = 0; l < bri.size(); ++l)
cout << bri[l].first << " - " << bri[l].second << endl;
}
return 0;
}