資源簡介
在—個遙遠的國家,Sark Mevo 所領導的政黨最終擊敗了Reguel Tekris王子領導的聯合黨派。Mevo希望鞏固他在首都地區的席位。首都由14個街區組成,這些街區將分組為多個選區。下圖是首都地區的示意圖。在圖中用數字1到14對這些街區進行了編號。每個街區中的另外兩個數字是預計該街區會投票給Mevo的選民數和該街區的選民總數。所有選民都必須投票,且選舉勝出方必須得到絕對多數選票。一個選區可以由多個相鄰的街區組成,且選區內總選民數應在30,000到100,000之間。如果兩個街區不相鄰,例如12和13,則它們不能組成一個選區。如果某個街區選民人數不少于50,000,則允許此街區單獨作為一個選區。但是由于Mevo本人就居住在街區10內,因此迫于輿論壓力,他不能將這個街區單獨作為一個選區。
請設計出一個將首都劃分為5個選區的方案,以使Mevo得到的席位數最多。如果這樣做有困難,可以嘗試劃分為6個選區。

代碼片段和文件信息
#include?
#include?
#include?
#define?MaxStackSize?14//最大棧容量
char?re_choose[]={“\n選擇非法,請輸入正確的編號...\n“};
typedef?struct?Street
{
int SNum;
int?Num;
}Street;//定義街區結構體
Street?str[MaxStackSize];//定義結構體長度
int?l[MaxStackSize][MaxStackSize]={ {01001000000000}
{00101000000000}
{00011000000000}
{00001000010000}
{00000100010000}
{00000011000000}
{00000001100000}
{00000000111000}
{00000000001100}
{00000000001010}
{00000000000110}
{00000000000001}
{00000000000001}
{00000000000000}};//表示相鄰街區的矩陣,1表示相鄰。0表示不相鄰
int?b[50][MaxStackSize];//用來存儲所有選區,1表示存在,初始全為0
void?AddData()//添加街區信息
{
str[0].SNum = 17500;
str[1].SNum = 15000;
str[2].SNum = 14200;
str[3].SNum = 42000;
str[4].SNum = 18000;
str[5].SNum = 9000;
str[6].SNum = 12000;
str[7].SNum = 10000;
str[8].SNum = 26000;
str[9].SNum = 34000;
str[10].SNum = 2500;
str[11].SNum = 27000;
str[12].SNum = 29000;
str[13].SNum = 15000;
str[0].Num = 30000;
str[1].Num = 50000;
str[2].Num = 20000;
str[3].Num = 70000;
str[4].Num = 20000;
str[5].Num = 40000;
str[6].Num = 30000;
str[7].Num = 30000;
str[8].Num = 40000;
str[9].Num = 60000;
str[10].Num = 10000;
str[11].Num = 60000;
str[12].Num = 40000;
str[13].Num = 40000;
}
typedef?struct
{
int? *element;? //一維數組
int top; //指向堆棧棧頂元素?
int MaxSize;? //可存儲的最多數據元素?
}?Stack;
Stack?SS1S2;
void?CreatStack?(Stack?&S)?//?構造一個最大容量為MaxStackSize?的堆棧S
{
??? S.MaxSize?=?MaxStackSize;
??? S.element?=?new?int?[S.MaxSize];
?? S.top?=?-1;
}
void?CreatStack2?(Stack?&S)?//?構造一個最大容量為50?的堆棧S
{
??? S.MaxSize?=?50;
??? S.element?=?new?int?[S.MaxSize];
?? S.top?=?-1;
}
int?JudgeS(int?k)//判斷街區是否相鄰,返回1表示相鄰
{
for(int?p=S.top;p>-1;p--)
{
if(l[S.element[p]][k])
{
return?1;
}
}
return?0;
}
bool?IsEmpty(Stack?&S)//?判斷堆棧S是否為空
{
if?(S.top?==?-1)???
{
return?true;
}
return??false;
}
bool?IsFull(Stack?&S)//?判斷堆棧S是否為滿
{
if?(S.top?>=?S.MaxSize-1)??
return?true;
return??false;
}
bool?Push(Stack?&S??int?&x)//?x進s棧,返回進棧后的狀態值
{
if?(IsFull(S))
return?false;
S.top++;
S.element[S.top]?=?x;
??? return?true;
}
bool?Pop(Stack?&S??int?&x)//?將s棧頂的值取至x中,返回出棧后的狀態值
{
if?(IsEmpty(S))???
return?false;
x?=?S.element[S.top];
S.top--;
???return?true;
}
void?Devide(int?w[]?int?s[]int?T)//分選區
{
int???k?=?0;
int ??i?=?0;
int???t?=?0;
int j=S.top;
float?f=0;
do??????????????????????????????????????????????//滿足總人數不大于100000人則進棧
{???????????????????????????????????????????????????????????????????????????????????????????????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????50176??2011-04-17?18:41??選區劃分?last\Debug\vc60.idb
?????文件??????61440??2011-04-17?18:41??選區劃分?last\Debug\vc60.pdb
?????文件?????254050??2011-04-17?18:41??選區劃分?last\Debug\分選區??last.exe
?????文件?????307644??2011-04-17?18:41??選區劃分?last\Debug\分選區??last.ilk
?????文件??????43907??2011-04-17?18:41??選區劃分?last\Debug\分選區??last.obj
?????文件?????307000??2011-04-17?17:38??選區劃分?last\Debug\分選區??last.pch
?????文件?????615424??2011-04-17?18:41??選區劃分?last\Debug\分選區??last.pdb
?????文件??????41984??2011-04-10?23:29??選區劃分?last\分選區\Debug\vc60.idb
?????文件??????53248??2011-04-10?23:29??選區劃分?last\分選區\Debug\vc60.pdb
?????文件?????180278??2011-04-10?23:15??選區劃分?last\分選區\Debug\分選區.exe
?????文件?????213624??2011-04-10?23:15??選區劃分?last\分選區\Debug\分選區.ilk
?????文件??????13056??2011-04-10?23:29??選區劃分?last\分選區\Debug\分選區.obj
?????文件?????220944??2011-04-10?22:36??選區劃分?last\分選區\Debug\分選區.pch
?????文件?????476160??2011-04-10?23:15??選區劃分?last\分選區\Debug\分選區.pdb
?????文件???????9211??2011-04-11?00:20??選區劃分?last\分選區\分選區.cpp
?????文件???????4286??2011-04-11?00:05??選區劃分?last\分選區\分選區.dsp
?????文件????????537??2011-04-10?22:04??選區劃分?last\分選區\分選區.dsw
?????文件??????41984??2011-04-11?00:21??選區劃分?last\分選區\分選區.ncb
?????文件??????49664??2011-04-11?00:21??選區劃分?last\分選區\分選區.opt
?????文件????????647??2011-04-10?23:29??選區劃分?last\分選區\分選區.plg
?????文件??????18531??2011-05-12?17:37??選區劃分?last\分選區??last.cpp
?????文件???????3475??2011-04-17?17:38??選區劃分?last\分選區??last.dsp
?????文件????????532??2011-04-17?21:23??選區劃分?last\分選區??last.dsw
?????文件??????41984??2011-05-12?17:36??選區劃分?last\分選區??last.ncb
?????文件??????48640??2011-05-12?17:36??選區劃分?last\分選區??last.opt
?????文件???????1208??2011-04-17?18:41??選區劃分?last\分選區??last.plg
?????文件?????384512??2010-11-29?17:04??選區劃分?last\選區劃分.doc
?????目錄??????????0??2011-10-24?10:48??選區劃分?last\分選區\Debug
?????目錄??????????0??2011-10-24?10:48??選區劃分?last\Debug
?????目錄??????????0??2011-10-24?10:48??選區劃分?last\分選區
............此處省略4個文件信息
- 上一篇:中國地質大學C++課件6
- 下一篇:PTA基礎編程答案
評論
共有 條評論