HDU 6631 line symmetric(枚舉)

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

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

第二種情況,有一個點不滿足要求,那么顯然這種情況只可能是奇數點的時候才出現,那么只需要將這個點移到對稱軸上則滿足要求,那么Yes。

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

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

多注意細節吧,現場wa到自閉。

數據:

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(){    //逆時針旋轉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){    //點積
 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){} //兩點確定直線
 89 };
 90 
 91 int relation(Point p,Line l){    //點和向量關系   1:左側   2:右側   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){        //點在直線上的投影
 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){            //點關于直線的對稱點
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 }

?

轉載于:https://www.cnblogs.com/dd-bond/p/11308155.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/247252.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/247252.shtml
英文地址,請注明出處:http://en.pswp.cn/news/247252.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

學習數字圖像處理經驗談

一、面向應用&#xff1a;層層分解、抓住要點 我們學習數字圖像處理的最終目的還是應用&#xff0c;不管是用它來研制產品還是研發項目抑或是研究課題&#xff0c;都要用數字圖像處理的理論、方法和技術來解決實際問題。在此過程中&#xff0c;提高效率是非常重要的&#xff0c…

讀javascript百煉成仙笑死筆記一

“自然是這樣的&#xff0c;但是我現在這樣改一下&#xff0c;你說結果是多少呢&#xff1f;”葉小凡詭異地笑了笑&#xff0c;然后打出一段比較奇特的代碼。 var a 1; var b; var sum (b a --a) a-- b; “噗&#xff01;”看到這段代碼&#xff0c;對面弟子差點一口老血…

C#調用存儲過程的通用類

usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Data.SqlClient;usingSystem.Collections;usingSystem.Data;//摘要&#xff1a;數據訪問助手。//作者&#xff1a;ZhiQiao//日期&#xff1a;2008/07/02namespaceZhiQiao.DataAccessHelper{ //存…

圖靈獎得主(一)

本文轉自&#xff1a;http://bbs.gxnu.edu.cn/bbsanc.php?path%2Fgroups%2FGROUP_5%2FProgramming%2Fother%2FM.1029997222.A A.M. Turing Award ACMs most prestigious technical award is accompanied by a prize of $25,000. It is given to an individual selected fo…

react-router-dom@6獲取路由傳參

目錄 參數獲取 1、子路由形式攜帶 2、問號(?)形式參數 3、事件跳轉傳參 router/index.tsx import App from "App"; import Home from "pages/Home"; import List from "pages/List"; import Detail from "pages/Detail"; import…

圖靈獎得主(二)

本文轉自&#xff1a;http://bbs.gxnu.edu.cn/bbsanc.php?path%2Fgroups%2FGROUP_5%2FProgramming%2Fother%2FM.1029997222.A 1987年度的圖靈獎授予了IBM沃特森研究中心老資格的研究員 約翰科克(Johncocke)。 科克是從機械到數學、又從數學轉到 計算機方向上來的學者。…

jQuery效果之滑動

jQuery 滑動方法有三種&#xff1a;slideDown()、slideUp()、slideToggle()。 jQuery slideDown() 方法用于向下滑動元素&#xff0c; 語法&#xff1a;$(selector).slideDown(speed,callback); 可選的 speed 參數規定效果的時長。它可以取以下值&#xff1a;"slow"、…

Error: This command has to be run with superuser privileges (under the root user on most systems).

意思是錯誤&#xff1a;此命令必須以超級用戶權限&#xff08;在大多數系統上以root用戶權限&#xff09;運行。所以當前的用戶是普通用戶&#xff0c;需要切換為超級用戶&#xff08;root用戶&#xff09;先輸入在命令行中輸入 su root 然后會出現Password&#xff1a;&#…

圖靈獎得主(三)

本文轉自&#xff1a;本文轉自&#xff1a;http://bbs.gxnu.edu.cn/bbsanc.php?path%2Fgroups%2FGROUP_5%2FProgramming%2Fother%2FM.1029997222.A 繼1979年度圖靈獎首次授予一位加拿大學者K.E.Iverson之后&#xff0c; 1989年度的圖靈 獎又一次授予加拿大學者威廉凱亨(Willia…

對微信公共號的理解

通過redirect_uri獲取code 通過code和appid 獲取access_token 進行鑒權 轉載于:https://www.cnblogs.com/zhouyideboke/p/11309752.html

vue3 v-model變化

概覽 就變化內容而言&#xff0c;此部分屬于高階內容&#xff1a; 非兼容&#xff1a;用于自定義組件時&#xff0c;v-model的 prop 和事件默認名稱已更改&#xff1a; prop&#xff1a;value -> modelValue&#xff1b;event&#xff1a;input -> update:modelValue&a…

圖靈獎得主(四)

本文轉自&#xff1a;本文轉自&#xff1a;本文轉自&#xff1a;http://bbs.gxnu.edu.cn/bbsanc.php?path%2Fgroups%2FGROUP_5%2FProgramming%2Fother%2FM.1029997222.A 1991年度的圖靈獎授予了愛丁堡大學計算機科學系教授羅 賓米爾納(Robin Milner)。米爾納是繼M.V.Wilkes(1…

sql 日期類型空值等于 1900-01-01

SQL server 中查詢&#xff1a;select cast( as datetime) 結果&#xff1a;1900-01-01 00:00:00.000 做為判斷條件的話&#xff0c;要注意。不能直接 轉載于:https://www.cnblogs.com/meng9527/p/11311765.html

koa洋蔥模型

Koa 和 Express 都會使用到中間件 Express的中間件是順序執行&#xff0c;從第一個中間件執行到最后一個中間件&#xff0c;發出響應如上圖 Koa是從第一個中間件開始執行&#xff0c;遇到 next 進入下一個中間件&#xff0c;一直執行到最后一個中間件&#xff0c;在逆序&#x…

圖靈獎得主(五)

[1993]斯坦恩斯--"打工"帶來的機遇 斯坦恩斯是學數學出身的。1958年他在卡爾頓學院(Carlton College)取 得數學學士學位后進入普林斯頓大學研究生院&#xff0c;用了3年時間就 取得博士學位&#xff0c;其博士論文課題是關于博奕論的。 斯坦恩斯跨進計算機科…

koa后端允許跨域

舉個例子 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8" /><meta http-equiv"X-UA-Compatible" content"IEedge" /><meta name"viewport" content"widthdevice-width…

python面向對象之繼承

面向對象之繼承 什么是面向對象的繼承&#xff1f; 繼承&#xff08;英語&#xff1a;inheritance&#xff09;是面向對象軟件技術當中的一個概念。如果一個類別A“繼承自”另一個類別B&#xff0c;就把這個A稱 為“B的子類別”&#xff0c;而把B稱為“A的父類別”也可以稱“B是…

美國正面臨“人才泡沫”破裂危機?

&#xff08;Jason Lane和Kevin Kinser/文&#xff09;最近&#xff0c;與教育有關的種種問題在美國社會引起了廣泛討論。首先巨額的學生貸款問題&#xff1a;根據美聯儲紐約分行在2012年11月發布的一份報告&#xff0c;全美學生貸款總額已經達到420億美元&#xff0c;其中新增…

ngrx學習筆記

什么是ngrx ngrx是Angular基于Rxjs的狀態管理&#xff0c;保存了Redux的核心概念&#xff0c;并使用RxJs擴展的Redux實現。使用Observable來簡化監聽事件和訂閱等操作。 在看這篇文章之前&#xff0c;已經假設你已了解rxjs和redux。 有條件的話請查看官方文檔進行學習理解。 所…

解決RM刪除沒有釋放空間問題

www172-18-8-12 log]$ df -h Filesystem Size Used Avail Use% Mounted on/dev/vda1 120G 101G 20G 84% /devtmpfs 7.8G 0 7.8G 0% /devtmpfs 7.8G 0 7.8G 0% /dev/shmtmpfs 7.8G 601M 7.2G 8% /run 我刪除文件時&#xff0c;直接用的rm 沒有加參數lf,結果空間沒有釋放 文件已經…