日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

HDU 6631 line symmetric(枚举)

發(fā)布時(shí)間:2023/12/13 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU 6631 line symmetric(枚举) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

首先能想到的是至少有一對相鄰點(diǎn)或者中間間隔一個(gè)點(diǎn)的點(diǎn)對滿足軸對稱,那么接下來只需要枚舉剩下的點(diǎn)對是否滿足至多移動(dòng)一個(gè)點(diǎn)可以滿足要求。

第一種情況,對于所有點(diǎn)對都滿足要求,那么Yes。

第二種情況,有一個(gè)點(diǎn)不滿足要求,那么顯然這種情況只可能是奇數(shù)點(diǎn)的時(shí)候才出現(xiàn),那么只需要將這個(gè)點(diǎn)移到對稱軸上則滿足要求,那么Yes。

第三種情況,有兩個(gè)點(diǎn)不滿足要求,然后我們需要枚舉這兩個(gè)點(diǎn)對應(yīng)的對稱點(diǎn)是否滿足要求,對于其中一個(gè)點(diǎn)的對稱點(diǎn)判斷他是否和之前所有點(diǎn)重合,以及判斷這個(gè)點(diǎn)是否在對稱軸上。

這樣還不夠,還需要考慮對于對稱軸兩邊的可能的對應(yīng)的對稱點(diǎn),他們是不是在對應(yīng)一側(cè),如果兩個(gè)點(diǎn)都不在對應(yīng)的一側(cè),說明這兩個(gè)點(diǎn)自交,則不能滿足要求,直接跳過。

多注意細(xì)節(jié)吧,現(xiàn)場wa到自閉。

數(shù)據(jù):

5 -100 -100 0 0 -100 100 2 -1 100 1 N7 -3 3 -5 -5 1 -3 -1 -3 0 2 5 -5 3 3 N

附圖說明:

1 // ——By DD_BOND 2 3 //#include<bits/stdc++.h> 4 //#include<unordered_map> 5 //#include<unordered_set> 6 #include<functional> 7 #include<algorithm> 8 #include<iostream> 9 //#include<ext/rope> 10 #include<iomanip> 11 #include<climits> 12 #include<cstring> 13 #include<cstdlib> 14 #include<cstddef> 15 #include<cstdio> 16 #include<memory> 17 #include<vector> 18 #include<cctype> 19 #include<string> 20 #include<cmath> 21 #include<queue> 22 #include<deque> 23 #include<ctime> 24 #include<stack> 25 #include<map> 26 #include<set> 27 28 #define fi first 29 #define se second 30 #define MP make_pair 31 #define pb push_back 32 33 typedef long long ll; 34 35 using namespace std; 36 37 const int MAXN=1e3+10; 38 const double eps=1e-12; 39 const double pi=acos(-1.0); 40 const ll INF=0x3f3f3f3f3f3f3f3f; 41 42 inline int dcmp(double x){ 43 if(fabs(x)<eps) return 0; 44 return (x>0? 1: -1); 45 } 46 47 inline double sqr(double x){ return x*x; } 48 49 struct Point{ 50 double x,y; 51 Point(){ x=0,y=0; } 52 Point(double _x,double _y):x(_x),y(_y){} 53 void input(){ scanf("%lf%lf",&x,&y); } 54 bool operator ==(const Point &b)const{ 55 return (dcmp(x-b.x)==0&&dcmp(y-b.y)==0); 56 } 57 Point operator +(const Point &b)const{ 58 return Point(x+b.x,y+b.y); 59 } 60 Point operator -(const Point &b)const{ 61 return Point(x-b.x,y-b.y); 62 } 63 Point operator *(double a){ 64 return Point(x*a,y*a); 65 } 66 Point operator /(double a){ 67 return Point(x/a,y/a); 68 } 69 double len2(){ //長度平方 70 return sqr(x)+sqr(y); 71 } 72 Point rotate_left(){ //逆時(shí)針旋轉(zhuǎn)90度 73 return Point(-y,x); 74 } 75 }; 76 77 inline double cross(Point a,Point b){ //叉積 78 return a.x*b.y-a.y*b.x; 79 } 80 81 inline double dot(Point a,Point b){ //點(diǎn)積 82 return a.x*b.x+a.y*b.y; 83 } 84 85 struct Line{ 86 Point s,e; 87 Line(){} 88 Line(Point _s,Point _e):s(_s),e(_e){} //兩點(diǎn)確定直線 89 }; 90 91 int relation(Point p,Line l){ //點(diǎn)和向量關(guān)系 1:左側(cè) 2:右側(cè) 3:在線上 92 int c=dcmp(cross(p-l.s,l.e-l.s)); 93 if(c<0) return 1; 94 else if(c>0) return 2; 95 else return 3; 96 } 97 98 Point projection(Point p,Line a){ //點(diǎn)在直線上的投影 99 return a.s+(((a.e-a.s)*dot(a.e-a.s,p-a.s))/(a.e-a.s).len2()); 100 } 101 102 Point symmetry(Point p,Line a){ //點(diǎn)關(guān)于直線的對稱點(diǎn) 103 Point q=projection(p,a); 104 return Point(2*q.x-p.x,2*q.y-p.y); 105 } 106 107 int vis[MAXN]; 108 vector<Line>st; 109 Point point[MAXN]; 110 111 int main(void){ 112 int T; scanf("%d",&T); 113 while(T--){ 114 int n,ans=0; scanf("%d",&n); 115 for(int i=0;i<n;i++) point[i].input(); 116 for(int i=0;i<n&&!ans;i++){ 117 int s=i,t=(i+1)%n; 118 Point mid=(point[s]+point[t])/2,vec=(point[s]-point[t]).rotate_left(); 119 Line line(mid,mid+vec); 120 int num=0,error=0; 121 memset(vis,0,sizeof(vis)); 122 while(!vis[s]&&!vis[t]){ 123 vis[s]=1,vis[t]=1; 124 Point p1=(point[s]+point[t])/2,dir=(point[s]-point[t]).rotate_left(); 125 Point p2=p1+dir; 126 if(dcmp(cross(point[i]-mid,vec))*dcmp(cross(point[s]-mid,vec))<0&&dcmp(cross(point[(i+1)%n]-mid,vec))*dcmp(cross(point[t]-mid,vec))<0) error=1; 127 if(relation(p1,line)==3&&relation(p2,line)==3){ 128 if(s!=t) num+=2; 129 else num++; 130 } 131 s=(s-1+n)%n,t=(t+1)%n; 132 } 133 if(error) continue; 134 if(num+1>=n) ans=1; 135 else if(num+2==n){ 136 s=i,t=(i+1)%n; 137 memset(vis,0,sizeof(vis)); 138 while(!vis[s]&&!vis[t]){ 139 vis[s]=1,vis[t]=1; 140 Point p1=(point[s]+point[t])/2,vec=(point[s]-point[t]).rotate_left(); 141 Point p2=p1+vec; 142 if(relation(p1,line)!=3||relation(p2,line)!=3){ 143 if(relation(point[s],line)!=3&&relation(point[t],line)!=3){ 144 int f1=0,f2=0; 145 Point s1=symmetry(point[s],line),s2=symmetry(point[t],line); 146 for(int j=0;j<n;j++) 147 if(point[j]==s1) 148 f1=1; 149 for(int j=0;j<n;j++) 150 if(point[j]==s2) 151 f2=1; 152 if(!f2||!f1) ans=1; 153 } 154 break; 155 } 156 s=(s-1+n)%n,t=(t+1)%n; 157 } 158 } 159 } 160 for(int i=0;i<n&&!ans;i++){ 161 int s=(i-1+n)%n,t=(i+1)%n; 162 Point mid=(point[s]+point[t])/2,vec=(point[s]-point[t]).rotate_left(); 163 Line line(mid,mid+vec); 164 int num=0,error=0; s=t=i; 165 memset(vis,0,sizeof(vis)); 166 while(!vis[s]&&!vis[t]){ 167 vis[s]=1,vis[t]=1; 168 Point p1=(point[s]+point[t])/2,dir=(point[s]-point[t]).rotate_left(); 169 Point p2=p1+dir; 170 if(dcmp(cross(point[(i-1+n)%n]-mid,vec))*dcmp(cross(point[s]-mid,vec))<0&&dcmp(cross(point[(i+1)%n]-mid,vec))*dcmp(cross(point[t]-mid,vec))<0) error=1; 171 if(relation(p1,line)==3&&relation(p2,line)==3){ 172 if(s!=t) num+=2; 173 else num++; 174 } 175 s=(s-1+n)%n,t=(t+1)%n; 176 } 177 if(error) continue; 178 if(num+1>=n) ans=1; 179 else if(num+2==n){ 180 s=t=i; 181 memset(vis,0,sizeof(vis)); 182 while(!vis[s]&&!vis[t]){ 183 vis[s]=1,vis[t]=1; 184 Point p1=(point[s]+point[t])/2,vec=(point[s]-point[t]).rotate_left(); 185 Point p2=p1+vec; 186 if(relation(p1,line)!=3||relation(p2,line)!=3){ 187 if(relation(point[s],line)!=3&&relation(point[t],line)!=3){ 188 int f1=0,f2=0; 189 Point s1=symmetry(point[s],line),s2=symmetry(point[t],line); 190 for(int j=0;j<n;j++) 191 if(point[j]==s1) 192 f1=1; 193 for(int j=0;j<n;j++) 194 if(point[j]==s2) 195 f2=1; 196 if(!f2||!f1) ans=1; 197 } 198 break; 199 } 200 s=(s-1+n)%n,t=(t+1)%n; 201 } 202 } 203 } 204 if(ans) puts("Y"); 205 else puts("N"); 206 } 207 return 0; 208 }

?

轉(zhuǎn)載于:https://www.cnblogs.com/dd-bond/p/11308155.html

總結(jié)

以上是生活随笔為你收集整理的HDU 6631 line symmetric(枚举)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。