Skip to content

Instantly share code, notes, and snippets.

@ryuichimatsumoto-single
Last active March 11, 2016 23:59
Show Gist options
  • Save ryuichimatsumoto-single/ea213397aae2cc09325e to your computer and use it in GitHub Desktop.
Save ryuichimatsumoto-single/ea213397aae2cc09325e to your computer and use it in GitHub Desktop.
アダムズ方式
#include<stdio.h>
#include<math.h>
#define NUM 2
//配列の合計の値を出力
int sum(double a[])
{
int i=0;
int result = 0;
for(i=0;i<NUM;i++)
{
result += (int)a[i];
}
return result;
}
//アダムズ方式の本体は、全てmainにて定義する
int main()
{
int people[NUM] = {75000,45000};
double seat[NUM] = {0.0,0.0};
int start_people = 1;
int end_people = 75000;
int max_seat = 4;
int i=0;
int j=0;
for(i=start_people;i<end_people;i++)
{
for(j=0;j<NUM;j++)
{
seat[j] = ceil((double)people[j]/(double)i);
}
//犠牲数確保と同時に終了
if(sum(seat) == max_seat)
{
printf("d=%d ",i);
break;
}
}
for(j=0;j<NUM;j++)
{
printf("%d番目の議席数=%f ",j,seat[j]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment