一、心得

 

二、题目及分析

 求1, 2x+1和3x+1队列的第100个数 

 

三、代码及结果

 

 1 //求1, 2x+1和3x+1队列的第100个数 
 2 //依次把队列中的2x+1和3x+1都取了 
 3 #include <iostream>
 4 using namespace std;
 5 
 6 int q[200]; 
 7 
 8 int main(){
 9     int head=1;
10     q[head]=1;
11     int two=1,three=1;
12     //求第100个数 
13     for(int i=1;i<=100;i++){
14         int x2=2*q[two]+1;
15         int x3=3*q[three]+1; 
16         if(x2==x3){
17             q[++head]=x2;
18             two++,three++;
19         }
20         else if(x2<x3){
21             q[++head]=x2;
22             two++;
23         }
24         else{
25             q[++head]=x3;
26             three++;
27         }
28     } 
29     cout<<q[100]<<endl;
30     
31         
32     return 0;
33 } 

队列2--集合

前十项

队列2--集合

相关文章:

  • 2021-09-19
  • 2021-08-15
  • 2021-12-09
  • 2021-09-28
  • 2021-10-23
  • 2021-09-24
  • 2022-01-20
猜你喜欢
  • 2021-08-18
  • 2021-11-01
  • 2021-05-15
  • 2021-11-17
  • 2022-12-23
  • 2021-08-02
相关资源
相似解决方案