1 #include<iostream> 2 using namespace std; 3 int a[10001]; 4 int b[10001]; 5 int ha=1,ta; 6 int hb=1,tb; 7 int n; 8 int tot=1; 9 int x=1; 10 int main() 11 { 12 int n; 13 cin>>n; 14 while(tot<=n) 15 { 16 cout<<x<<" "; 17 ta++; 18 tb++; 19 a[ta]=2*x+1; 20 b[tb]=3*x+1; 21 if(a[ha]>b[hb]) 22 { 23 x=b[hb]; 24 hb++; 25 } 26 else if(a[ha]<b[hb]) 27 { 28 x=a[ha]; 29 ha++; 30 } 31 else 32 { 33 x=a[ha]; 34 ha++; 35 hb++; 36 } 37 tot++; 38 } 39 //cout<<tot; 40 return 0; 41 }
stl:
1 #include<iostream> 2 #include<queue> 3 using namespace std; 4 int tot=1; 5 int x=1; 6 int main() 7 { 8 queue<int>a; 9 queue<int>b; 10 int n; 11 cin>>n; 12 while(tot<=n) 13 { 14 cout<<x<<" "; 15 a.push(2*x+1); 16 b.push(3*x+1); 17 if(a.front()>b.front()) 18 { 19 x=b.front(); 20 b.pop(); 21 } 22 else if(a.front()<b.front()) 23 { 24 x=a.front(); 25 a.pop(); 26 } 27 else 28 { 29 x=a.front(); 30 a.pop(); 31 b.pop(); 32 } 33 tot++; 34 } 35 return 0; 36 }