- 求职 : 机器学习
- 论坛徽章:
- 79
|
本帖最后由 zsszss0000 于 2015-05-20 19:15 编辑
- #include <iostream>
- using namespace std;
- #define NUM_SCHOOL 6
- #define NUM_TEACHER 6
- #define NUM_COURSE 14
- #define NUM_COURSE_EACH 3
- #define RX 0
- #define JF 1
- #define JG 2
- #define SM 3
- #define SB 4
- #define BS 5
- #define PF 6
- #define PG 7
- #define GD 8
- #define FF 9
- #define BJ 10
- #define PJ 11
- #define MZ 12
- #define FG 13
- /*
- A1: BJ FF PG
- A2: FG BJ RX
- A3: JG FG SM
- A4: PF JG SM
- A5: PF MZ BS
- A6: SB MZ JF
- B1: JG PF PG
- B2: PF RX SB
- B3: BJ BS PG
- B4: PJ BS BJ
- B5: PG SM FF
- B6: JG SM PG
- C1: JG FG GD
- C2: BJ JG SB
- C3: PG BS FG
- C4: JG SB PF
- C5: BS FF BJ
- C6: FG SM PJ
- D1: PG FG GD
- D2: RX PG JG
- D3: FG JG BS
- D4: SB BS FG
- D5: BJ BS SB
- D6: BJ PF FF
- E1: PG PF PJ
- E2: SB PF GD
- E3: JF GD JG
- E4: BJ FF PF
- E5: MZ SB PF
- E6: SB FF GD
- F1: BJ SM PF
- F2: SB PJ RX
- F3: BS FG PJ
- F4: MZ FG RX
- F5: FG BJ BS
- F6: RX SM FG
- */
- const int aaa[NUM_SCHOOL][NUM_TEACHER][NUM_COURSE_EACH]=
- {
- {
- { BJ,FF,PG },
- { FG,BJ,RX },
- { JG,FG,SM },
- { PF,JG,SM },
- { PF,MZ,BS },
- { SB,MZ,JF },
- },
- {
- { JG,PF,PG },
- { PF,RX,SB },
- { BJ,BS,PG },
- { PJ,BS,BJ },
- { PG,SM,FF },
- { JG,SM,PG },
- },
- {
- { JG,FG,GD },
- { BJ,JG,SB },
- { PG,BS,FG },
- { JG,SB,PF },
- { BS,FF,BJ },
- { FG,SM,PJ },
- },
- {
- { PG,FG,GD },
- { RX,PG,JG },
- { FG,JG,BS },
- { SB,BS,FG },
- { BJ,BS,SB },
- { BJ,PF,FF },
- },
- {
- { PG,PF,PJ },
- { SB,PF,GD },
- { JF,GD,JG },
- { BJ,FF,PF },
- { MZ,SB,PF },
- { SB,FF,GD },
- },
- {
- { BJ,SM,PF },
- { SB,PJ,RX },
- { BS,FG,PJ },
- { MZ,FG,RX },
- { FG,BJ,BS },
- { RX,SM,FG },
-
- },
- };
- int aval_teacher_table[NUM_SCHOOL][NUM_TEACHER];
- int cord_course[NUM_COURSE][NUM_SCHOOL*NUM_TEACHER];
- int init_aval_teacher_table(int aval_teacher_table[][NUM_TEACHER])
- {
- int i=0;
- int j=0;
- for(i=0;i<NUM_SCHOOL;i++)
- {
- for(j=0;j<NUM_TEACHER;j++)
- {
- aval_teacher_table[i][j]=1;
- }
- }
- return 1;
- }
- int init_course_table(int cord_course[][NUM_SCHOOL*NUM_TEACHER])
- {
- int i=0;
- int j=0;
- for(i=0;i<NUM_COURSE;i++)
- {
- for(j=0;j<NUM_SCHOOL*NUM_TEACHER;j++)
- {
- cord_course[i][j]=0;
- }
- }
- return 1;
- }
- int chosed_teacher[6];
- int best_chosed_teacher[6];
- int best_price;
- int check_chose_teacher(int teacher[])
- {
- int ret = 0;///<默认失败
- int tmp[6]={0,0,0,0,0,0};
- int i=0;
- for(i=0;i<6;i++)
- {
- tmp[teacher[i]%6]=1;
- }
- for(i=0;i<6;i++)
- {
- if(tmp[i]==0)
- break;
- }
- if(i==6)
- {
- // cout<<"teacher arrangement is valid!"<<endl;
- /* 说明6个序号都存在,此时还要添加 */
- return 1;
- }
- else
- {
- // cout<<"teacher arrangement is not valid!"<<endl;
- return 0;
- }
- }
- int update_best_teacher(int teacher[])
- {
- int i;
- int j;
- int num;
- int tmp_price=0;
- int tmp_index;
- // for(i=0;i<6;i++)
- // {
- // cout<<"teacher is "<<teacher[i]<<"\t";
- // }
- // cout<<endl;
- /* 此处需要用到course_teacher表格 */
- for(i=0;i<NUM_COURSE;i++)
- {
- num=0;
- for(j=0;j<6;j++)
- {
- tmp_index=teacher[j];
- if(cord_course[i][tmp_index])
- {
- num++;
- }
- }
- if(num==3)
- {
- tmp_price+=4;
- }
- else if(num==4)
- {
- tmp_price+=6;
- }
- else if(num==5)
- {
- tmp_price+=8;
- }
- else if(num==6)
- {
- tmp_price+=10;
- }
- else
- {
- ///<do nothing
- }
- }
- if(tmp_price>=best_price)
- {
- for(i=0;i<6;i++)
- {
- cout<<"teacher is "<<teacher[i]<<"\t";
- }
- cout<<"total price is "<<tmp_price;
- cout<<endl;
- for(i=0;i<6;i++)
- {
- best_chosed_teacher[i]=teacher[i];
- }
- best_price=tmp_price;
- }
- }
- int zuhe(int k,int n)
- {
- int x1;
- int x2;
- int x3;
- int x4;
- int x5;
- int x6;
- for (int x1 = 0; x1 <= n-k; x1++)
- for (int x2 = x1+1; x2 <= n-k+1; x2++)
- for (int x3 = x2+1; x3 <= n-k+2; x3++)
- for (int x4 = x3+1; x4 <= n-k+3; x4++)
- for (int x5 = x4+1; x5 <= n-k+4; x5++)
- for (int x6 = x5+1; x6 <= n-k+5; x6++)
- {
- chosed_teacher[0]=x1;
- chosed_teacher[1]=x2;
- chosed_teacher[2]=x3;
- chosed_teacher[3]=x4;
- chosed_teacher[4]=x5;
- chosed_teacher[5]=x6;
- // cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<" "<<x5<<" "<<x6<<endl;
- if(check_chose_teacher(chosed_teacher))
- {
- update_best_teacher(chosed_teacher);
- }
- else
- {
- break;
- }
- }
- }
- int main ( int argc, char *argv[] )
- {
- best_price=0;
- init_aval_teacher_table(aval_teacher_table);
- init_course_table(cord_course);
- int i=0;
- int j=0;
- int k=0;
- int tmp=0;
- for(i=0;i<NUM_SCHOOL;i++)
- {
- for(j=0;j<NUM_TEACHER;j++)
- {
- for(k=0;k<NUM_COURSE_EACH;k++)
- {
- cord_course[aaa[i][j][k]][6*i+j]=1;
-
- }
- }
- }
- cout<<" "<<"A1A2A3A4A5A6B1B2B3B4B5B6C1C2C3C4C5C6D1D2D3D4D5D6E1E2E3E4E5E6F1F2F3F4F5F6 total"<<endl;
- for(i=0;i<NUM_COURSE;i++)
- {
- switch(i)
- {
- case 0:
- cout<<"RX:";
- break;
- case 1:
- cout<<"JF:";
- break;
- case 2:
- cout<<"JG:";
- break;
- case 3:
- cout<<"SM:";
- break;
- case 4:
- cout<<"SB:";
- break;
- case 5:
- cout<<"BS:";
- break;
- case 6:
- cout<<"PF:";
- break;
- case 7:
- cout<<"PG:";
- break;
- case 8:
- cout<<"GD:";
- break;
- case 9:
- cout<<"FF:";
- break;
- case 10:
- cout<<"BJ:";
- break;
- case 11:
- cout<<"PJ:";
- break;
- case 12:
- cout<<"MZ:";
- break;
- case 13:
- cout<<"FG:";
- break;
- default:
- break;
- }
- tmp=0;
- for(j=0;j<NUM_SCHOOL*NUM_TEACHER;j++)
- {
- if(cord_course[i][j])
- {
- tmp++;
- }
-
- cout<<cord_course[i][j]<<" ";
- }
- cout<<" "<<tmp<<endl;
- }
- zuhe(6,36);
- cout<<"the best teacher arrangement is "<<endl;
- for(i=0;i<6;i++)
- {
- cout<<best_chosed_teacher[i]<<"\t";
- }
- cout<<endl;
- cout<<"the price is "<<endl;
- cout<<best_price<<endl;
- return 1;
- }/* end of function main */
复制代码
- A1A2A3A4A5A6B1B2B3B4B5B6C1C2C3C4C5C6D1D2D3D4D5D6E1E2E3E4E5E6F1F2F3F4F5F6 total
- RX:0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 6
- JF:0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 2
- JG:0 0 1 1 0 0 1 0 0 0 0 1 1 1 0 1 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 10
- SM:0 0 1 1 0 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 7
- SB:0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 1 0 0 1 0 0 1 1 0 1 0 0 0 0 10
- BS:0 0 0 0 1 0 0 0 1 1 0 0 0 0 1 0 1 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 0 1 0 10
- PF:0 0 0 1 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 1 0 1 1 0 1 0 0 0 0 0 11
- PG:1 0 0 0 0 0 1 0 1 0 1 1 0 0 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 9
- GD:0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0 5
- FF:1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 0 6
- BJ:1 1 0 0 0 0 0 0 1 1 0 0 0 1 0 0 1 0 0 0 0 0 1 1 0 0 0 1 0 0 1 0 0 0 1 0 11
- PJ:0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 5
- MZ:0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 4
- FG:0 1 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 12
- teacher is 0 teacher is 1 teacher is 2 teacher is 3 teacher is 4 teacher is 5 total price is 0
- teacher is 0 teacher is 1 teacher is 2 teacher is 3 teacher is 10 teacher is 11 total price is 14
- teacher is 0 teacher is 1 teacher is 2 teacher is 3 teacher is 34 teacher is 35 total price is 14
- teacher is 0 teacher is 1 teacher is 2 teacher is 23 teacher is 27 teacher is 28 total price is 14
- teacher is 0 teacher is 1 teacher is 2 teacher is 33 teacher is 34 teacher is 35 total price is 16
- teacher is 0 teacher is 1 teacher is 5 teacher is 14 teacher is 21 teacher is 22 total price is 16
- teacher is 0 teacher is 1 teacher is 5 teacher is 20 teacher is 21 teacher is 22 total price is 16
- teacher is 0 teacher is 1 teacher is 8 teacher is 9 teacher is 34 teacher is 35 total price is 16
- teacher is 0 teacher is 1 teacher is 8 teacher is 21 teacher is 34 teacher is 35 total price is 16
- teacher is 0 teacher is 1 teacher is 8 teacher is 23 teacher is 27 teacher is 28 total price is 16
- teacher is 0 teacher is 1 teacher is 8 teacher is 33 teacher is 34 teacher is 35 total price is 16
- teacher is 0 teacher is 1 teacher is 9 teacher is 14 teacher is 34 teacher is 35 total price is 16
- teacher is 0 teacher is 1 teacher is 9 teacher is 20 teacher is 34 teacher is 35 total price is 16
- teacher is 0 teacher is 1 teacher is 9 teacher is 32 teacher is 34 teacher is 35 total price is 16
- teacher is 0 teacher is 1 teacher is 11 teacher is 14 teacher is 21 teacher is 22 total price is 16
- teacher is 0 teacher is 1 teacher is 14 teacher is 21 teacher is 34 teacher is 35 total price is 16
- teacher is 0 teacher is 1 teacher is 14 teacher is 33 teacher is 34 teacher is 35 total price is 16
- teacher is 0 teacher is 1 teacher is 20 teacher is 21 teacher is 34 teacher is 35 total price is 16
- teacher is 0 teacher is 1 teacher is 20 teacher is 33 teacher is 34 teacher is 35 total price is 16
- teacher is 0 teacher is 1 teacher is 21 teacher is 32 teacher is 34 teacher is 35 total price is 16
- teacher is 0 teacher is 1 teacher is 32 teacher is 33 teacher is 34 teacher is 35 total price is 16
- teacher is 0 teacher is 2 teacher is 3 teacher is 13 teacher is 34 teacher is 35 total price is 16
- teacher is 0 teacher is 3 teacher is 10 teacher is 11 teacher is 19 teacher is 20 total price is 16
- teacher is 0 teacher is 5 teacher is 8 teacher is 13 teacher is 21 teacher is 22 total price is 16
- teacher is 0 teacher is 5 teacher is 8 teacher is 19 teacher is 21 teacher is 22 total price is 16
- teacher is 0 teacher is 5 teacher is 9 teacher is 22 teacher is 31 teacher is 32 total price is 16
- teacher is 0 teacher is 7 teacher is 8 teacher is 11 teacher is 21 teacher is 22 total price is 16
- teacher is 0 teacher is 7 teacher is 8 teacher is 23 teacher is 27 teacher is 28 total price is 16
- teacher is 0 teacher is 7 teacher is 8 teacher is 27 teacher is 28 teacher is 29 total price is 16
- teacher is 0 teacher is 7 teacher is 16 teacher is 23 teacher is 26 teacher is 27 total price is 16
- teacher is 0 teacher is 8 teacher is 9 teacher is 19 teacher is 22 teacher is 23 total price is 16
- teacher is 0 teacher is 8 teacher is 11 teacher is 13 teacher is 21 teacher is 22 total price is 18
- teacher is 0 teacher is 8 teacher is 19 teacher is 23 teacher is 27 teacher is 28 total price is 18
- teacher is 0 teacher is 9 teacher is 16 teacher is 23 teacher is 31 teacher is 32 total price is 18
- teacher is 1 teacher is 2 teacher is 30 teacher is 33 teacher is 34 teacher is 35 total price is 20
- teacher is 2 teacher is 3 teacher is 6 teacher is 7 teacher is 10 teacher is 11 total price is 20
- teacher is 6 teacher is 8 teacher is 11 teacher is 13 teacher is 21 teacher is 22 total price is 20
- teacher is 6 teacher is 15 teacher is 25 teacher is 26 teacher is 28 teacher is 29 total price is 20
- teacher is 12 teacher is 13 teacher is 20 teacher is 21 teacher is 22 teacher is 23 total price is 20
- teacher is 12 teacher is 15 teacher is 25 teacher is 26 teacher is 28 teacher is 29 total price is 20
- the best teacher arrangement is
- 12 15 25 26 28 29
- the price is
- 20
复制代码
teacher is 1 teacher is 2 teacher is 30 teacher is 33 teacher is 34 teacher is 35 total price is 20
teacher is 2 teacher is 3 teacher is 6 teacher is 7 teacher is 10 teacher is 11 total price is 20
teacher is 6 teacher is 8 teacher is 11 teacher is 13 teacher is 21 teacher is 22 total price is 20
teacher is 6 teacher is 15 teacher is 25 teacher is 26 teacher is 28 teacher is 29 total price is 20
teacher is 12 teacher is 13 teacher is 20 teacher is 21 teacher is 22 teacher is 23 total price is 20
teacher is 12 teacher is 15 teacher is 25 teacher is 26 teacher is 28 teacher is 29 total price is 20
teacher is 1 teacher is 2 teacher is 30 teacher is 33 teacher is 34 teacher is 35 total price is 20
这个组合表示
A2 A3 F1 F4 F5 F6
上面这些组合的和为20,如果A学校的校长,任选其中一种选择的话,那么B校长要在此基础之上,进行一个选择。
我觉得这道题目,还可以有下面几种变形:
1、保持原来要求不变,但是要求总体得到的奖励最大(即六所学校得到的奖励之和最大)
2、保持原来要求不变,但是要求总体得到的奖励最小(即A要选择一个其他5家得到的和最小,B要在此基础之上选择一个使得其他四家得到的最小,以此类推)
|
|