| Profilo di Nilson人活一口气!FotoBlogElenchi | Guida |
枚举法。买鸡枚举法:将所有情况一一列举
/*100.00块买100只鸡*/ /*小鸡:0.5块/每只*/ /*母鸡:5.0块/每只*/ /*公鸡:3.0块/每只*/ #include<iostream.h> void main() { int x,y,z; //x是小鸡的个数,y公鸡的个数,z母鸡的个数 for(x=0;x<=100;x++) { for(y=0;y<=33;y++) { for(z=0;z<=20;z++) { if(x+y+z==100 && x*0.5+y*3+z*5==100) cout<<"小鸡的个数:"<<x<<" 公鸡的个数:"<<y<<"母鸡的个数:"<<z<<endl; } } } } |
|
|