本文整理汇总了C++中vi::end方法的典型用法代码示例。如果您正苦于以下问题:C++ vi::end方法的具体用法?C++ vi::end怎么用?C++ vi::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vi
的用法示例。
在下文中一共展示了vi::end方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(){
scanf("%d%d", &N, &M);
int a;
for(int i = 0; i < N; ++i){
scanf("%d", &a);
cities.push_back(a);
}
for(int i = 0; i < M; ++i){
scanf("%d", &a);
towers.push_back(a);
}
s = 0;
e = INF;
while(s < e){
r = (s+e)/2;
bool covered = true;
for(int i = 0; i < N; i++){
int low = lower_bound(towers.begin(), towers.end(), cities[i]) - towers.begin();
int high = upper_bound(towers.begin(), towers.end(), cities[i]) - towers.begin();
if(towers[low] == cities[i]) continue;
if(low != 0) low--; // the one before cities[i]
if(high == M) high--;
if(abs(towers[low] - cities[i]) <= r || abs(towers[high] - (ll) cities[i]) <= r) continue;
covered = false;
break;
}
if(covered){
e = r;
}else{
s = r+1;
}
}
cout << s << endl;
}
示例2: checkConstraints
bool checkConstraints(vi remStrings, int n, vbs A, vi f){
sort(remStrings.begin(), remStrings.end());
vector<vi> strings;
for(int i=0; i<itv.size(); i++){
vi cur = itv[i];
if(binary_search(remStrings.begin(), remStrings.end(), i)){
continue;
}
strings.push_back(cur);
}
for(int i=0; i<A.size(); i++){
if(A[i].size()==1) continue;
set<vi> s;
for(int j=0; j<strings.size(); j++){
vi curV;
for(int k=0; k<n; k++){
if(!A[i][k]) continue;
curV.push_back(strings[j][k]);
}
s.insert(curV);
if(s.size()>f[i]) return false;
}
}
return true;
}
示例3: 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();
}
示例4: printGroups
void printGroups(vi & visited)
{
std::sort(visited.begin(), visited.end());
out("visited: ");
for(vi::const_iterator cit = visited.begin(); cit!=visited.end();++cit){
out("%d ",*cit);
}
out("\n");
vi groups;
vi::const_iterator pit = visited.begin();
vi::const_iterator cit = pit+1;
int currcnt = 1;
while(cit != visited.end()) {
if(*cit == *pit) {
currcnt++;
}
else {
groups.push_back(currcnt);
currcnt = 1;
pit = cit;
}
cit++;
}
groups.push_back(currcnt);
std::sort(groups.begin(), groups.end(), std::greater<int>());
int i = 0;
for(vi::const_iterator cit = groups.begin(); cit!=groups.end() && i < 10;++cit, i++){
printf("%d ",*cit);
}
printf("\n");
}
示例5: main
int main()
{
FILE *in = fopen (PROBLEM_NAME".in","r");
FILE *out = fopen (PROBLEM_NAME".out","w");
int k;
fscanf(in, "%d %d ", &n, &k);
for (int i = 0; i < n; ++i) {
used.push_back(false);
tin.push_back(0);
fup.push_back(0);
vi l;
g.push_back(l);
}
for (int i = 0; i < k; ++i) {
int x, y;
fscanf(in, "%d %d ", &x, &y);
g[x-1].push_back(y-1);
g[y-1].push_back(x-1);
}
timer = 0;
dfs(0);
sort(ans.begin(), ans.end());
ans.erase( unique( ans.begin(), ans.end() ), ans.end() );
fprintf(out, "%d\n", (int)ans.size());
for (size_t i = 0; i < ans.size(); ++i) {
fprintf(out, "%d\n", ans[i]+1);
}
fclose(in);
fclose(out);
return 0;
}
示例6: hapusRadius
void hapusRadius(vi & Lingkaran, int inp){
vi::const_iterator a = Lingkaran.begin();
for (vi::const_iterator i = Lingkaran.begin(); i<Lingkaran.end();++i){
if (*i == inp){
Lingkaran.erase(Lingkaran.begin()+(i-a));
i=Lingkaran.end();
}
}
}
示例7: 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;
}
示例8: main
int main() {
// freopen("fence8.in", "r", stdin);
// freopen("fence8.out", "w", stdout);
int i,j,k;
scanf("%d", &n);
boards = vi(n);
for(i=0; i<n; i++) scanf("%d", &boards[i]);
sort(boards.begin(), boards.end());
scanf("%d", &m);
rails = vi(m);
for(i=0; i<m; i++) scanf("%d", &rails[i]);
sort(rails.begin(), rails.end());
cummSum = vi(m);
cummSum[rails.size()-1]=rails[rails.size()-1];
for(int i=rails.size()-2; i>=0; i--){
cummSum[i]=rails[i]+cummSum[i+1];
}
options = vector<vvi>(n);
for(int i=0; i<n; i++){
find_options(i, boards[i], vi(), 0);
//sort options with more rails first
vii p;
for(int j=0; j<options[i].size(); j++){
p.push_back(ii(options[i][j].size(), j));
}
sort(p.rbegin(), p.rend());
vvi newOptions(options[i].size());
for(int j=0; j<p.size(); j++){
newOptions[j]=options[i][p[j].second];
}
options[i]=newOptions;
}
// sort boards with less number of options first
vii p;
for(int i=0; i<n; i++){
p.push_back(ii(options[i].size(), i));
}
sort(p.begin(), p.end());
vector<vvi> newOptions(n);
for(int i=0; i<n; i++){
newOptions[i]=options[p[i].second];
}
options=newOptions;
printf("%d\n", recur(0, bitset<BSM>()));
return 0;
}
示例9: CariRadius
void CariRadius(vi & Lingkaran, int inp){
while(binary_search(Lingkaran.begin(),Lingkaran.end(),inp)){
hapusRadius(Lingkaran,inp);
}
if (!binary_search(Lingkaran.begin(),Lingkaran.end(),inp)){
printf("Tidak ada lingkaran dengan radius %d\n",inp);
}
}
示例10: IsStonglyConnected
bool IsStonglyConnected() {
V.assign(N,0);
dfs(0, G1);
if(find(ALL(V), 0) != V.end()) return false; // if all nodes are not reachable from a given node(say v), then return false.
V.assign(N,0);
dfs(0, G2);
if(find(ALL(V), 0) != V.end()) return false; // if any other node cannot reach to v, then return false.
return true;
}
开发者ID:avinashw50w,项目名称:Data-structures-and-Algorithms,代码行数:15,代码来源:Check+whether+a+graph+is+Strongly+Connected.cpp
示例11: main
int main(){
while(scanf("%d %d %d %d", &n, &a, &b, &c) != EOF){
AdjList.assign(n + 1, vi());
stop = false;
distBC = 0;
for(int i = 0; i < n - 1; i++){
int u, v; scanf("%d %d", &u, &v);
AdjList[u].push_back(v);
AdjList[v].push_back(u);
}
bfs(b);
sort(pathBC.begin(), pathBC.end());
int w = bfs2(a);
queue<int> q; q.push(w);
vi dist(n + 1, INF); dist[w] = 0;
while(!q.empty()){
int u = q.front(); q.pop();
for(int j = 0; j < (int) AdjList[u].size(); j++){
int v = AdjList[u][j];
if(dist[v] == INF){
dist[v] = dist[u] + 1;
q.push(v);
}
}
}
printf("%.6lf\n", 1.0 - (dist[b]*1.0)/(distBC*1.0));
}
return 0;
}
示例12: findSolution
int findSolution() {
p = vi(n, -1);
int ans = 0;
for (;;) {
bool g = false;
for (int i = 0; i < n; i++) if (ty[i] == 0 && p[i] < 0) {
was = vb(n, false);
chain.clear();
if (dfs(i)) {
reverse(chain.begin(), chain.end());
assert(chain.size() % 2 == 0);
for (int i2 = 0; i2 < chain.size(); i2 += 2) {
p[chain[i2]] = chain[i2 + 1];
p[chain[i2 + 1]] = chain[i2];
}
g = true;
ans++;
break;
}
}
if (!g) break;
}
return ans;
}
示例13: 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;
}
}
示例14: main
int main()
{
v.assign(101, vector<ii>());
visited.assign(101, 0);
while(true)
{
topo.clear();
for(i=0;i<101;++i)
visited[i]=0;
scanf("%d %d", &n, &m);
if(!n && !m)
break;
for(i=1;i<=n;++i)
v[i].clear();
while(m--)
{
scanf("%d %d", &x, &y);
v[x].push_back(make_pair(y, 1));
}
for(i=1;i<=n;++i)
{
if(!visited[i])
dfs(i);
}
reverse(topo.begin(), topo.end());
for(i=0;i<n;++i)
{
if(i>0)
putchar(' ');
printf("%d", topo[i]);
}
putchar('\n');
}
return 0;
}
示例15: 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]);
}