动态题目问题,我们需要自动AC机......
T1:
看到划掉的那部分了吗,没错,考试中途改题面了......
然而我只会写15分爆搜......
计算几何+构造,不改了,爆搜滚粗了......
以下为官方题解:
15分爆搜代码:
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<cmath> 6 #include<cstdlib> 7 #define debug cout 8 typedef long long int lli; 9 using namespace std; 10 const int maxn=1e4+1e1; 11 const double pi = acos(-1.0); 12 13 struct Point { 14 lli x,y; 15 inline friend Point operator - (const Point &a,const Point &b) { 16 return (Point){a.x-b.x,a.y-b.y}; 17 } 18 inline friend lli operator * (const Point &a,const Point &b) { 19 return a.x * b.y - a.y * b.x; 20 } 21 inline double dis() const { 22 return sqrt(x*x+y*y); 23 } 24 friend bool operator < (const Point &a,const Point &b) { 25 return a.x < b.x; 26 } 27 }ps[maxn]; 28 int a[maxn],b[maxn],cnt; 29 bool used[maxn]; 30 long double sum; 31 int n; 32 33 inline bool iscorss(const Point &pa,const Point &pb,const Point &ta,const Point &tb) { 34 if( min(ta.x,tb.x) > max(pa.x,pb.x) 35 || min(pa.x,pb.x) > max(ta.x,tb.x) 36 || min(ta.y,tb.y) > max(pa.y,pb.y) 37 || min(pa.y,pb.y) > max(ta.y,tb.y) ) 38 return 0; 39 return ( (__int128)((tb-pa)*(pb-pa)) * ((pb-pa)*(ta-pa)) > 0 && (__int128)((tb-pb)*(pa-pb)) * ((pa-pb)*(ta-pb)) > 0 ); 40 } 41 inline bool judge(const int &nx,const int &ny) { 42 for(int i=1;i<=cnt;i++) { 43 if( iscorss(ps[a[i]],ps[b[i]],ps[nx],ps[ny]) ) return 0; 44 } 45 return 1; 46 } 47 inline bool checkans() { 48 double ret = 0; 49 for(int i=1;i<=cnt;i++) ret += ( ps[a[i]] - ps[b[i]] ).dis(); 50 return ret * pi >= sum * 2.0; 51 } 52 inline void finish() { 53 if( !checkans() ) return; 54 for(int i=1;i<=cnt;i++) printf("%d %d\n",a[i],b[i]); 55 exit(0); 56 } 57 inline void dfs(int pos) { 58 if( pos > n << 1 ) return finish(); 59 if( used[pos] ) return dfs(pos+1); 60 used[pos] = 1; 61 for(int i=pos+1;i<=n<<1;i++) if( !used[i] && judge(pos,i) ) { 62 used[i] = 1 , a[++cnt] = pos , b[cnt] = i; 63 dfs(pos+1); 64 used[i] = 0 , --cnt; 65 } 66 used[pos] = 0; 67 } 68 69 int main() { 70 scanf("%d",&n); 71 if( n > 15 ) return 0; 72 for(int i=1;i<=n<<1;i++) scanf("%lld%lld",&ps[i].x,&ps[i].y); 73 for(int i=1,a,b;i<=n;i++) { 74 scanf("%d%d",&a,&b) , 75 sum += ( ps[a] - ps[b] ).dis(); 76 } 77 dfs(1); 78 return 0; 79 }