Untitled
unknown
plain_text
a year ago
2.0 kB
5
Indexable
#1 185 #2 302 #3 7 #4 207 #5 100 #6 165 #7 326 #8 283 #9 145 #10 451 #11 326 #12 105 #13 418 #14 162 #15 232 #16 223 #17 419 #18 103 #19 68 #20 402 #21 55 #22 258 #23 196 #24 179 #25 369 #26 379 #27 326 #28 364 #29 360 #30 26 #31 17 #32 178 #33 61 #34 276 #35 268 #36 275 #37 137 #38 23 #39 345 #40 75 #41 413 #42 37 #43 122 #44 194 #45 380 #46 97 #47 84 #48 312 #49 359 #50 74 #include <iostream> using namespace std; #define MAX 105 int map[MAX][MAX]; int K,R,M,N; int visit_loca[MAX]; int visit_pizza[25]; int max_vl; struct Pizza{ int x, y; }; Pizza pizza[25]; struct Solitaire{ int x,y; int value; }; Solitaire loca[MAX]; void write_data(){ cin>>M; for(int i=1; i<=M;i++){ cin>> pizza[i].x>>pizza[i].y; } cin>>N; for(int i=1; i<=N;i++){ cin>> loca[i].x>>loca[i].y>>loca[i].value; visit_loca[i]=0; } } int check_kc(int x1, int y1, int x2, int y2){ int kc_bp=(x1-x2)*(x1-x2)+(y1-y2)*( y1-y2); return (kc_bp<=R*R); } void write_map(){ for(int i=1; i<=M; i++){ for(int j=1; j<=N;j++){ if(check_kc(pizza[i].x, pizza[i].y,loca[j].x,loca[j].y)==1){ map[i][j]=1; }else{ map[i][j]=0; } } } } int tinh(int index){ int result=0; for(int i=1; i<=N; i++){ if(map[index][i] && !visit_loca[i]){ result+=loca[i].value; } } return result; } void backtrack(int step,int count,int last_pizza){ if( step ==K){ if(count >max_vl){ max_vl=count; } return; } //backtrack for(int j=last_pizza+1;j<=M;j++){ int back_up[MAX]; int sum=tinh(j); for(int i=1; i<=N;i++){ back_up[i]=visit_loca[i]; } for(int i=1;i<=N;i++){ if(map[j][i] && !visit_loca[i]){ visit_loca[i]=1; } } backtrack(step+1,count+sum,j); for(int i=1; i<=N;i++){ visit_loca[i]=back_up[i]; } } } int main(){ freopen("input.txt","r",stdin); int T; cin>>T; for(int tc=1; tc<=T;tc++){ cin>>K>>R; write_data(); max_vl=0; write_map(); //read_map(); backtrack(0,0,0); cout<<"#"<<tc<<" "; cout<<max_vl<<endl; } return 0; } -- your code goes here
Editor is loading...
Leave a Comment