0% found this document useful (0 votes)
10 views4 pages

Mapas: Cerr Visited (I) (J) " " ) Cerr Endl )

The document contains various C++ code snippets demonstrating different algorithms and data structures, including BFS, bit manipulation, and sorting algorithms like insertion and shell sort. It includes input/output operations, vector manipulations, and condition checks. The code is interspersed with comments and debugging statements for clarity.

Uploaded by

Jonatan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

Mapas: Cerr Visited (I) (J) " " ) Cerr Endl )

The document contains various C++ code snippets demonstrating different algorithms and data structures, including BFS, bit manipulation, and sorting algorithms like insertion and shell sort. It includes input/output operations, vector manipulations, and condition checks. The code is interspersed with comments and debugging statements for clarity.

Uploaded by

Jonatan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

cerr << visited[i][j] << " ";

MAPAS } cerr << endl;


#include<bits/stdc++.h> }*/
using namespace std; visited[x][y] = true;
int main(){ queue<pair<int,int>> q;
ios_base:: sync_with_stdio(false); q.push({x,y});
cin.tie(NULL),cout.tie(NULL); while( !q.empty() ){
int n; int currx = q.front().first;
cin>>n; int curry = q.front().second;
int k; cerr << currx << " " << curry << endl;
cin>>k; q.pop();
int a[n]; for(int i = 0 ; i < 4 ; i++){
unordered_map<int ,int>m; int posx = currx + dx[i];
for(int i=0; i<n ; i++){ int posy = curry + dy[i];
cin>>a[i]; if( oki(posx,posy) && !visited[posx]
} [posy] ){
for (int x = 0; x < min(k,19); x++){ visited[posx][posy] = true;
for (int j = 0; j < n; j++){ q.push({posx,posy});
m[a[j]]++; }
} }
for (int i = 0; i < n; i++){ }
a[i]=m[a[i]]; }
}
m.clear(); int main(){
} cin >> n >> m;
for (int i = 0; i < n; i++){ vector<string> v(n);
cout<<a[i]<<" "; for(int i = 0; i < n ; i++){
}cout<<endl; cin >> v[i];
}
} vector<vector<bool>> visited (n,
BFSENGRILLA vector<bool> (m, false));
#include <iostream> //int visited[n][m];
#include <string> for(int i = 0 ; i < n; i++){
#include <vector> for(int j = 0 ; j< m ; j++){
#include <queue> if( v[i][j] == '#' ){
using namespace std; visited[i][j] = true;
}
int dx[4]{1,0,-1,0}; }
int dy[4]{0,1,0,-1}; }
int ans = 0;
int n,m; for(int i = 0 ; i < n; i++){
for(int j = 0 ; j< m ; j++){
bool oki(int x, int y){ if( !visited[i][j] ){
return x >= 0 && x < n && y >= 0 && y < ans++;
m; cerr << i << " " << j << endl;
} bfs(i,j,visited);
}
void bfs(int x, int y,vector<vector<bool>> }
&visited){ }
/*for(int i = 0 ; i < n; i++){ cout << ans << endl;
for(int j = 0 ; j < m ; j++){ return 0;
}
for(int i=0;i<m;i++){
BITSDES ans^=a[i];
/*#include <bits/stdc++.h> cout<<ans<<endl;
using namespace std; }
int main () { }
int n;
cin>>n;
cout<<(1<<n)<<endl;
cout<<(n>>1)<<endl; ejer_set
for(int mask=0;mask<(1<<n);mask++){ #include <bits/stdc++.h>
for(int i=n-1;i>=0;i--){ using namespace std;
if((mask>>i)&1){ int main () {
cout<<"1"; int n;
} cin>>n;
else{ set<int>st;
cout<<"0"; int v;
} vector<int> a;
} for ( int i=0; i<n ; i++){
cout<<endl; cin>>v;
} st.insert(v);
return 0; }
} int k=st.count(3);
#include <bits/stdc++.h> cout<<"cantidad de 3 "<<k<<endl;
using namespace std; int l= st.size();
int main () { for (int k:st){
string n; cout<<k<<" ";
cin>>n; }cout<<endl;
int z=n.size(); if(st.find(3)!= st.end()){ cout<<" hay el
for(int mask=0;mask<(1<<z);mask++){ numeros "<<endl;}else{cout <<"no hay el
for(int i=z-1;i>=0;i--){ nuemero "<<endl;}
if((mask>>i)&1){ if( st.count(3) ){ cout<<"hay el numero
cout<<n[i]; "<<endl;}else{cout<<"no hay el
} numero"<<endl;}
else{ cout<<" la cantidad "<<l << endl;
cout<<""; }
}
}
cout<<endl;
}
Ejercicio1
return 0; #include <bits/stdc++.h>
}*/ using namespace std;
int main () {
#include <bits/stdc++.h> int n;
using namespace std; cin>>n;
int main () { vector <int> a(n,5);
int m; //a.push_back(3);
int ans=0; /* for (int &d:a){
cin>>m; cin>>d;
int a[m]; }*/
for(int i=0;i<m;i++){ //a.pop_back();
cin>>a[i]; for (int d=0; d<4; d++){
} if(a[d]%2==0){
a.erase(a.begin()+d);
}else{a.insert(a.begin()+d+2,1);}
}
guia10ejer2
// a.clear(); #include <iostream>
for (int d:a){ using namespace std;
cout<<d<<" "; int main(){
} int x,bm,s=0;
cout<<endl; do{cout<<"inserte un numero mayor
/* for(int i=0; i<n; i++){ cero"<<endl;
cout<<a[i]<<" "; cin>>x;
}*/ }
/* for (int i = 0; i <n; i++) while (x<=0);
{ bm=x;
a[i]=0; while(x>0){
} s=s+1;
for (int d:a){ x=x/10;
cout<<d<<" "; }
}*/ cout<<"el numero de los digitos
cout<<endl; "<<bm<< " es: "<<s;
} }

Ejerd J
#include <bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; #define debug1(A) if(debug)
int main () { {cerr<<#A<<" :"<<A<<endl;}
string s; bool debug={1};
int j; #define fore(i,a,b) for (auto i = a; i < b; i++)
cin>>j; using namespace std;
for(int k =0; k<j ; k++){ bool ok(int act, int l){
cin>>s; if(act>0 && act< l+1){ return
int n; true; }else{ return false; }
n=s.size(); }
vector<int>dp(n+1); int main(){
if(s[0]==s[1]){ dp[0]=1; }else{ dp[0]=2; } int l,m,n,comer;
cin>>n;
if(s[n-1]==s[n-2]){dp[n-1]=1;}else{dp[n- cin>>m;
1]=2;} cin>>l;
cin>>comer;
for( int i=1 ; i< n-1; i++ ){ int vec[l+2]={};
if(s[i]==s[i-1] || s[i]==s[i+1] ){ int h;
dp[i]=1; for (int i = 0; i < comer; i++){
}else{dp[i]==2;} cin>>h;
} vec[h]=1;
for(int i=0; i<n; i++){ }
if(dp[i]==1) vector<int>visit(l+2,0);
{cout<<s[i];}else{cout<<s[i]<<s[i];} queue<int>q;
} q.push(0);
cout<<endl; visit[0]=1;
} int ans=0;
} while (q.size()){
int act=q.front();
debug1(act) }
// cout<<" actual "<<act<<endl; cout<<endl;
q.pop();
if(vec[act]){ans++;} }
if(ok( act +n,l) && !visit[act+n] ){
q.push(act+n);
visit[act+n]=1;
}
if(ok( act -m,l) && !visit[act-m] ){
q.push(act-m);
visit[act-m]=1;
}
debug1(q.size())
}
cout<<ans<<endl;
fore(i, 0,3){ debug1(ans)}
}

Po
#include <iostream>
using namespace std;
void insercion(int arreglo[], int n){
for(int i=1; i<n; i++){
int j=i;
while(j>0 && arreglo[j]<arreglo[j-1]){
swap(arreglo[j],arreglo[j-1]);j--;
}
}

}
void shell(int arreglo[], int n){
for (int k = n/2; k >0 ; k=k/2){
for(int i=k; i<n; i++){
int j=i;
while(j>=k && arreglo[j-k]>arreglo[j]){
swap(arreglo[j],arreglo[j-k]);j=j-k;
}
}
}
}
int main(){
int n;
cin>>n;
int arreglo[n];
for (int i = 0; i < n; i++){
arreglo[i]=rand()%100+1;
}
shell(arreglo,n);
for (int i = 0; i < n; i++)
{
cout<<arreglo[i]<<" ";

You might also like