/* * File: main.cpp * Author: kalin * * Created on December 29, 2015, 10:18 AM */ #include #include #include // std::next_permutation, std::sort #include #include using namespace std; const int MAX_TIME = 4.8 * CLOCKS_PER_SEC; struct Point{ int x,y; }; int N,M; int perm[101]; Point villages[101]; int wires[100*3-5][2]; int placed_wires[100*3-5]; int placed_wires_cnt=0; int pointing_wires[100*3-5]; int pointing_wires_cnt=0; int placed_plants[101]; int placed_plants_cnt=0; struct Solution{ int perm[101]; int placed_plants[101]; int cnt; }; Solution sol; void input(){ ifstream in; in.open("electricity.in"); in >> N >> M; for(int i=0; i> villages[i].x >> villages[i].y; } for(int i=0; i> wires[i][0] >> wires[i][1]; wires[i][0] -= 1; wires[i][1] -= 1; } in.close(); } void output(){ ofstream out; out.open ("electricity.out"); int K=0; for(int i=0; i= 1) return false; if(b.x == 0) return false; else k = ( c.x + l*d.x - a.x ) / b.x; if(k <= 0 || k >= 1) return false; return true; } bool intersectPerm(int a, int b){ return intersect( villages[perm[wires[a][0]]], villages[perm[wires[a][1]]], villages[perm[wires[b][0]]], villages[perm[wires[b][1]]] ); } bool plantAt(int plant, int wire){ Point t = villages[perm[plant]], a = villages[perm[wires[wire][0]]], b = villages[perm[wires[wire][1]]]; b.x -= a.x; b.y -= a.y; double k=-1.0; if( b.x == 0 && b.y == 0 ){ return false; } else if( b.x == 0 ){ k = (double)( t.y - a.y )/b.y; if(abs(t.x-a.x) >= 1) return false; } else if( b.y == 0 ){ k = (double)( t.x - a.x )/b.x; if(abs(t.y-a.y) >= 1) return false; } else { double k1 = (double)( t.y - a.y )/b.y, k2 = (double)( t.x - a.x )/b.x; if(abs(k1-k2) < 1) k = k1; } return 0 < k && k < 1; } void rpermute(){ for( int i = N-1; i > 0; i-- ){ int j = rand() % (i+1); int temp = perm[j]; perm[j] = perm[i]; perm[i] = temp; } } void init_pointing(int plant){ pointing_wires_cnt = 0; for(int i=0; i sol.cnt){ for(int i=0;i