Skip to content

Instantly share code, notes, and snippets.

@ryuichimatsumoto-single
Created March 13, 2016 11:19
Show Gist options
  • Save ryuichimatsumoto-single/5b91d52eeb7ba6218022 to your computer and use it in GitHub Desktop.
Save ryuichimatsumoto-single/5b91d52eeb7ba6218022 to your computer and use it in GitHub Desktop.
アダムズ方式(2)
#include<stdio.h>
#include<math.h>
#define NUM 47
#define CHAR_PREFECTURE_MAX 256
#define MAX_SEAT 295
//配列の合計の値を出力
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()
{
char prefecture[NUM][CHAR_PREFECTURE_MAX] =
{
"北海道",
"青森県",
"岩手県",
"宮城県",
"秋田県",
"山形県",
"福島県",
"茨城県",
"栃木県",
"群馬県",
"埼玉県",
"千葉県",
"東京都",
"神奈川県",
"新潟県",
"富山県",
"石川県",
"福井県",
"山梨県",
"長野県",
"岐阜県",
"静岡県",
"愛知県",
"三重県",
"滋賀県",
"京都府",
"大阪府",
"兵庫県",
"奈良県",
"和歌山県",
"鳥取県",
"島根県",
"岡山県",
"広島県",
"山口県",
"徳島県",
"香川県",
"愛媛県",
"高知県",
"福岡県",
"佐賀県",
"長崎県",
"熊本県",
"大分県",
"宮崎県",
"鹿児島県",
"沖縄県"
};
int people[NUM] =
{5506419,
1373339,
1330147,
2348165,
1085997,
1168924,
2029064,
2969770,
2007683,
2008068,
7194556,
6216289,
13159388,
9048331,
2374450,
1093247,
1169788,
806314,
863075,
2152449,
2080773,
3765007,
7410719,
1854724,
1410777,
2636092,
8865245,
5588133,
1400728,
1002198,
588667,
717397,
1945276,
2860750,
1451338,
785491,
995842,
1431493,
764456,
5071968,
849788,
1426779,
1817426,
1196529,
1135233,
1706242,
1392818
};
//1人別枠方式の場合の配列
int least_one_people[NUM] =
{12,
4,
4,
6,
3,
3,
5,
7,
5,
5,
15,
13,
25,
18,
6,
3,
3,
2,
2,
5,
5,
8,
15,
5,
4,
6,
19,
12,
4,
3,
2,
2,
5,
7,
4,
2,
3,
4,
2,
11,
2,
4,
5,
3,
3,
5,
4
};
double seat[NUM] =
{0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,//10
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,//20
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,//30
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,//40
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0
};
long long int start_people = 1;
long long int end_people = 13159388;
long long int max_seat = 295;
long long int i=0;
long long 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=%lld\n",i);
printf("県名,アダムズ方式 旧方式, 差\n");
//printf("d=%lld\n",i);
//printf("<table><tr><td>県名</td><td>アダムズ方式</td><td>旧方式,</td><td>差</td></tr>\n");
//printf("県名,アダムズ方式,旧方式,差\n");
break;
}
}
for(j=0;j<NUM;j++)
{
//printf("%d番目の議席数=%f ",j,seat[j]);
//printf("%s目の議席数=%d 旧方式の場合=%d, 差=%d\n",prefecture[j],(int)seat[j],least_one_people[j],(int)seat[j]-least_one_people[j]);
//printf("<tr><td>%s</td><td>%d</td><td>%d</td><td>%d</tr>\n",prefecture[j],(int)seat[j],least_one_people[j],(int)seat[j]-least_one_people[j]);
printf("%s,%d,%d,%d\n",prefecture[j],(int)seat[j],least_one_people[j],(int)seat[j]-least_one_people[j]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment