fork download
  1. #include<stdio.h>
  2. #include<math.h>
  3.  
  4. #define NUM 2
  5. //配列の合計の値を出力
  6. int sum(double a[])
  7. {
  8. int i=0;
  9. int result = 0;
  10. for(i=0;i<NUM;i++)
  11. {
  12. result += (int)a[i];
  13. }
  14. return result;
  15. }
  16.  
  17. //アダムズ方式の本体は、全てmainにて定義する
  18.  
  19. int main()
  20. {
  21. int people[NUM] = {75000,45000};
  22. double seat[NUM] = {0.0,0.0};
  23. int start_people = 1;
  24. int end_people = 75000;
  25. int max_seat = 4;
  26. int i=0;
  27. int j=0;
  28.  
  29. for(i=start_people;i<end_people;i++)
  30. {
  31. for(j=0;j<NUM;j++)
  32. {
  33. seat[j] = ceil((double)people[j]/(double)i);
  34. }
  35. //犠牲数確保と同時に終了
  36. if(sum(seat) == max_seat)
  37. {
  38. printf("d=%d ",i);
  39. break;
  40. }
  41. }
  42. for(j=0;j<NUM;j++)
  43. {
  44. printf("%d番目の議席数=%f ",j,seat[j]);
  45. }
  46. return 0;
  47. }
Success #stdin #stdout 0s 2156KB
stdin
Standard input is empty
stdout
d=37500 0番目の議席数=2.000000 1番目の議席数=2.000000