1 #include<iostream> 2 using namespace std; 3 int main(){ 4 int num=0; 5 int i,j,k; 6 for(i=0;i<4;i++){ 7 for(j=0;j<4;j++){ 8 k=8-i-j; 9 if(k<=6){ 10 num++; 11 cout<<"time"<<num<<"\t"<<"red"<<i<<"\t"<<"white"<<j<<"\t"<<"black"<<k<<endl; 12 } 13 } 14 } 15 return 0; 16 }
1 #include<iostream> 2 using namespace std; 3 int main(){ 4 int total; 5 int a=11; 6 int i; 7 for(i=4;i>0;i--){ 8 a=(a*(i+1)+1)/i; 9 cout<<a<<endl; 10 } 11 total=a; 12 cout<<"原来有"<<total<<"条鱼"<<endl; 13 }
逆向思维
1 #include<iostream> 2 using namespace std; 3 int main(){ 4 int i,j,x,flag=0; 5 for(i=23;flag==0;i+=2){ 6 for(j=1,x=i;j<=4&&x>=11;j++){ 7 if((x+1)%(j+1)==0) 8 x-=(x+1)/(j+1); 9 else 10 { 11 x=0; 12 break; 13 } 14 if(j==4&&x==11){ 15 cout<<"原来鱼缸里有"<<i<<"条金鱼"<<endl; 16 flag=1; 17 } 18 } 19 } 20 return 0; 21 }
正向思维
标签:11,main,int,18,namespace,2023,using,include From: https://www.cnblogs.com/xuxingkai/p/17331146.html