fork download
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5.  
  6. int main(){
  7. int a[5]={1,1,2,3,2};
  8. int b[5]={0,2,1,2,6};//上限值
  9. int c[5]={0,0,0,0,0};//用來記錄超過限制的格子(先歸零)
  10. int tmp;
  11. int tmp2;
  12. int tmp3;
  13. int i,j;
  14. for(j=0;j<5;j++){
  15. c[j]=b[j]-a[j];
  16. }
  17. for(j=0;j<5;j++){
  18. if(c[j]<0)
  19. tmp2=abs(c[j]); //取正值,然後將此值分配給其他未滿的格子
  20. for(i=0;i<tmp2;i++){ //還要注意分配之後 該格子有沒有滿
  21. do{
  22. tmp3=rand()%5;
  23. a[tmp3]++;
  24.  
  25. }while (c[j]>0); //若滿了再分給其他格<---這段不知道該怎麼寫
  26. }
  27. }
  28. // 第24行~第30行 有疑問~!!!
  29.  
  30. return 0;
  31. }
  32.  
  33. //重新分配後 a陣列的值 分別多少?
Time limit exceeded #stdin #stdout 5s 2720KB
stdin
Standard input is empty
stdout
Standard output is empty