poj

链接:https://vjudge.net/problem/POJ-3449
思路:真是对作文题绝望,但是1A的感觉好爽,这个题太多细节了,包括输入括号前的空格要考虑,输入读入方法,以及正方形长方形剩余点的计算,其实真正的判断反而不难,枚举所有边看是否不规范相交就行了,输出还要排序输出,反正就是翻译题,不过确实很锻炼码量啊。。。。。

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198

#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

typedef double db;

const db eps = 1e-10;
const db pi = acos(-1.0);

int (db x) {
return x<-eps?-1:x>eps;
}

db myacos(db x){
if(x<-1) x = -1;
if(x>1) x = 1;
return acos(x);
}

db myasin(db x){
if(x<-1) x = -1;
if(x>1) x = 1;
return asin(x);
}

db mysqrt(db x){
return x<0?0:sqrt(x);
}

typedef struct P {
db x, y;
P(db x = 0, db y = 0) : x(x), y(y) {}
P operator+(P r){return P(x+r.x,y+r.y);}
P operator-(P r){return P(x-r.x,y-r.y);}
P operator*(db r){return P(x*r,y*r);}
P operator/(db r){return P(x/r,y/r);}
bool operator<(const P &r)const{return x<r.x||(x==r.x&&y<r.y);}
bool operator==(const P &r)const{return dcmp(x-r.x)==0&&dcmp(y-r.y)==0;}

void read(){ scanf(" (%lf,%lf)", &x, &y); }
}V;

//向量a的极角
db Angle(const V& v) {
return atan2(v.y, v.x);
}

//向量点积
db Dot(V A, V B) { return A.x*B.x + A.y*B.y; }

//向量长度
db Length(V A) { return mysqrt(Dot(A, A)); }

//向量夹角
db Angle(V A, V B) { return myacos(Dot(A, B) / Length(A) / Length(B)); }

//向量叉积
db Cross(V A, V B) { return A.x*B.y - A.y*B.x; }

char s[20];
int n;

P GetLineIntersection(P p, V v, P q, V w) {
V u = p - q;
db t = Cross(w, u)/Cross(v, w);
return p+v*t;
}

//判断点是否在点段上,不包含端点
bool OnSegment(P p, P a1, P a2) {
return dcmp(Cross(a1-p, a2-p) == 0 && dcmp((Dot(a1-p, a2-p)) < 0));
}

//向量逆时针旋转rad度(弧度)
V Rotate(V A, db rad) {
return V(A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));
}

struct node{
P a[25];
int n;
char ch;
}r[200];

bool SegmentProperIntersection(P a1, P a2, P b1, P b2) {
db c1 = Cross(a2-a1, b1-a1), c2 = Cross(a2-a1, b2-a1);
db c3 = Cross(b2-b1, a1-b1), c4 = Cross(b2-b1, a2-b1);
return dcmp(c1)*dcmp(c2) < 0 && dcmp(c3)*dcmp(c4) < 0;
}

//不规范相交
bool on(P a1, P a2, P b1, P b2){
if(OnSegment(a1, b1, b2))return true;
if(OnSegment(a2, b1, b2))return true;
if(OnSegment(b1, a1, a2))return true;
if(OnSegment(b2, a1, a2))return true;
if(a1 == b1 || a1 == b2 || a2 == b1 || a2 == b2)return true;
return SegmentProperIntersection(a1, a2, b1, b2);
}

bool check(int x, int y){
for(int i = 1; i <= r[x].n; i++){
for(int j = 1; j <= r[y].n; j++){
if(on(r[x].a[i], r[x].a[i - 1], r[y].a[j], r[y].a[j - 1])){
// if(x == 0 && y == 2)printf("%.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2fn", r[x].a[i].x, r[x].a[i].y,r[x].a[i - 1].x, r[x].a[i - 1].y, r[y].a[j].x, r[y].a[j].y, r[y].a[j - 1].x, r[y].a[j - 1].y);
return true;
}
}
}
return false;
}


bool cmp(node &x, node &y){
return x.ch < y.ch;
}

bool cmp1(int x, int y){
return r[x].ch < r[y].ch;
}

int main(){
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
while(1){
n = 0;
while(scanf("%s", s) && s[0] != '-' && s[0] != '.'){
r[n].ch = s[0];
scanf("%s", s);
if(s[0] == 's'){
r[n].a[0].read();
r[n].a[2].read();
V v1 = r[n].a[2] - r[n].a[0];
V v2 = Rotate(v1, pi / 2);
V v3 = Rotate(v1, -pi / 2);
P mid = (r[n].a[0] + r[n].a[2]) / 2;
r[n].a[1] = mid + (v2) / 2;
r[n].a[3] = mid + (v3) / 2;
r[n].n = 4;
n++;
}
else if(s[0] == 't'){
r[n].n = 3;
for(int i = 0; i < 3; i++)r[n].a[i].read();
n++;
}
else if(s[0] == 'l'){
r[n].n = 2;
for(int i = 0; i < 2; i++){
r[n].a[i].read();
}
n++;
}
else if(s[0] == 'p'){
scanf("%d", &r[n].n);
for(int i = 0; i < r[n].n; i++)r[n].a[i].read();
n++;
}
else{
r[n].n = 4;
for(int i = 0; i < 3; i++)r[n].a[i].read();
r[n].a[3] = r[n].a[2] + r[n].a[0] - r[n].a[1];
n++;
}
}

for(int i = 0; i < n; i++)r[i].a[r[i].n] = r[i].a[0];
sort(r, r + n, cmp);

for(int i = 0; i < n; i++){
vector<int> res;
for(int j = 0; j < n; j++){
if(i == j)continue;
if(check(i, j))res.push_back(j);
}
if(!res.size()){
printf("%c has no intersectionsn", r[i].ch);
continue;
}
sort(res.begin(), res.end(), cmp1);
printf("%c intersects with", r[i].ch);
if(res.size() == 1)printf(" %cn", r[res[0]].ch);
else if(res.size() == 2) printf(" %c and %cn", r[res[0]].ch, r[res[1]].ch);
else{
for(int j = 0; j < res.size() - 1; j++){
printf(" %c,", r[res[j]].ch);
}
printf(" and %cn", r[res[res.size() - 1]].ch);
}
}
puts("");
if(s[0] == '.')break;
}
return 0;
}