新的一周 > <
好像这周 开学?
----------------
8.22
早起写个暴力先 T 一发..一天都精神
poj 1556 The Doors
POJ 干嘛G++交wa,C++交A
要是不看discuss 不知道该怎么debug了...
建图然后 floyed.
对于两个点,判断这两点 形成的线段 和 它们 所在门之间 的线段 有没有交点
如果有交点,说明这两点 是不可以相互到达的,设为 INF要不然就是两点 之间的距离
1 #include <cstdio> 2 #include <algorithm> 3 #include <cmath> 4 #include <vector> 5 using namespace std; 6 7 const int maxn = 205; 8 const int INF = (1<<30)-1; 9 10 //lrj计算几何模板 11 struct Point 12 { 13 double x, y; 14 int pos; 15 Point(double x=0, double y=0) :x(x),y(y) {} 16 }; 17 typedef Point Vector; 18 19 Point read_point(void) 20 { 21 double x, y; 22 int pos; 23 scanf("%lf%lf", &x, &y); 24 return Point(x, y); 25 } 26 27 const double EPS = 1e-10; 28 29 //向量+向量=向量 点+向量=点 30 Vector operator + (Vector A, Vector B) { return Vector(A.x + B.x, A.y + B.y); } 31 32 //向量-向量=向量 点-点=向量 33 Vector operator - (Vector A, Vector B) { return Vector(A.x - B.x, A.y - B.y); } 34 35 //向量*数=向量 36 Vector operator * (Vector A, double p) { return Vector(A.x*p, A.y*p); } 37 38 //向量/数=向量 39 Vector operator / (Vector A, double p) { return Vector(A.x/p, A.y/p); } 40 41 bool operator < (const Point& a, const Point& b) 42 { return a.x < b.x || (a.x == b.x && a.y < b.y); } 43 44 int dcmp(double x) 45 { if(fabs(x) < EPS) return 0; else return x < 0 ? -1 : 1; } 46 47 bool operator == (const Point& a, const Point& b) 48 { return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0; } 49 50 /**********************基本运算**********************/ 51 52 //点积 53 double Dot(Vector A, Vector B) 54 { return A.x*B.x + A.y*B.y; } 55 //向量的模 56 double Length(Vector A) { return sqrt(Dot(A, A)); } 57 58 //向量的夹角,返回值为弧度 59 double Angle(Vector A, Vector B) 60 { return acos(Dot(A, B) / Length(A) / Length(B)); } 61 62 //叉积 63 double Cross(Vector A, Vector B) 64 { return A.x*B.y - A.y*B.x; } 65 66 //向量AB叉乘AC的有向面积 67 double Area2(Point A, Point B, Point C) 68 { return Cross(B-A, C-A); } 69 70 //向量A旋转rad弧度 71 Vector VRotate(Vector A, double rad) 72 { 73 return Vector(A.x*cos(rad) - A.y*sin(rad), A.x*sin(rad) + A.y*cos(rad)); 74 } 75 76 //将B点绕A点旋转rad弧度 77 Point PRotate(Point A, Point B, double rad) 78 { 79 return A + VRotate(B-A, rad); 80 } 81 82 //求向量A向左旋转90°的单位法向量,调用前确保A不是零向量 83 Vector Normal(Vector A) 84 { 85 double l = Length(A); 86 return Vector(-A.y/l, A.x/l); 87 } 88 89 /**********************点和直线**********************/ 90 91 //求直线P + tv 和 Q + tw的交点,调用前要确保两条直线有唯一交点 92 Point GetLineIntersection(Point P, Vector v, Point Q, Vector w) 93 { 94 Vector u = P - Q; 95 double t = Cross(w, u) / Cross(v, w); 96 return P + v*t; 97 }//在精度要求极高的情况下,可以自定义分数类 98 99 //P点到直线AB的距离 100 double DistanceToLine(Point P, Point A, Point B) 101 { 102 Vector v1 = B - A, v2 = P - A; 103 return fabs(Cross(v1, v2)) / Length(v1); //不加绝对值是有向距离 104 } 105 106 //点到线段的距离 107 double DistanceToSegment(Point P, Point A, Point B) 108 { 109 if(A == B) return Length(P - A); 110 Vector v1 = B - A, v2 = P - A, v3 = P - B; 111 if(dcmp(Dot(v1, v2)) < 0) return Length(v2); 112 else if(dcmp(Dot(v1, v3)) > 0) return Length(v3); 113 else return fabs(Cross(v1, v2)) / Length(v1); 114 } 115 116 //点在直线上的射影 117 Point GetLineProjection(Point P, Point A, Point B) 118 { 119 Vector v = B - A; 120 return A + v * (Dot(v, P - A) / Dot(v, v)); 121 } 122 123 //线段“规范”相交判定 124 bool SegmentProperIntersection(Point a1, Point a2, Point b1, Point b2) 125 { 126 double c1 = Cross(a2-a1, b1-a1), c2 = Cross(a2-a1, b2-a1); 127 double c3 = Cross(b2-b1, a1-b1), c4 = Cross(b2-b1, a2-b1); 128 return dcmp(c1)*dcmp(c2)<0 && dcmp(c3)*dcmp(c4)<0; 129 } 130 131 //判断点是否在线段上 132 bool OnSegment(Point P, Point a1, Point a2) 133 { 134 Vector v1 = a1 - P, v2 = a2 - P; 135 return dcmp(Cross(v1, v2)) == 0 && dcmp(Dot(v1, v2)) < 0; 136 } 137 138 double dis(Point a,Point b){ 139 return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y)); 140 } 141 142 Point p[maxn*maxn]; 143 int n,tot; 144 145 struct Line{ 146 double y[5]; 147 double x; 148 int pos; 149 }; 150 151 Line line[maxn]; 152 double d[maxn][maxn]; 153 154 void solve(){ 155 for(int i = 1;i <= tot;i++){ 156 for(int j = 1;j <= tot;j++){ 157 if(i == j) d[i][j] = 0.0; 158 else d[i][j] = 1.0*INF; 159 } 160 } 161 162 for(int i = 1;i <= tot;i++){ 163 for(int j = i+1;j <= tot;j++){ 164 if(p[i].pos == p[j].pos) continue; 165 int l = p[i].pos; 166 int r = p[j].pos; 167 if(r == l+1) d[i][j] = dis(p[i],p[j]); 168 int ok = 0; 169 for(int k = l+1;k < r;k++){ 170 Point o1,o2,o3,o4,o5,o6; 171 double x = line[k].x; 172 o1 = Point(x,0.0); 173 o2 = Point(x,line[k].y[1]); 174 o3 = Point(x,line[k].y[2]); 175 o4 = Point(x,line[k].y[3]); 176 o5 = Point(x,line[k].y[4]); 177 o6 = Point(x,10.0); 178 if(SegmentProperIntersection(p[i],p[j],o1,o2)) ok = 1; 179 if(SegmentProperIntersection(p[i],p[j],o3,o4)) ok = 1; 180 if(SegmentProperIntersection(p[i],p[j],o5,o6)) ok = 1; 181 } 182 if(ok == 0) d[i][j] = d[j][i] = dis(p[i],p[j]); 183 } 184 } 185 186 /*for(int i = 1;i <= tot;i++){ 187 printf("p[%d].x = %lf y = %lf pos = %d\n",i,p[i].x,p[i].y,p[i].pos); 188 } 189 190 for(int i = 1;i <= tot;i++){ 191 for(int j = 1;j <= tot;j++) printf("d[%d][%d] = %lf\n",i,j,d[i][j]); 192 }*/ 193 194 for(int k = 1;k <= tot;k++){ 195 for(int i = 1;i <= tot;i++){ 196 for(int j = 1;j <= tot;j++) 197 d[i][j] = min(d[i][j],d[i][k]+d[k][j]); 198 } 199 } 200 printf("%0.2lf\n",d[1][tot]); 201 } 202 203 int main(){ 204 while(scanf("%d",&n) != EOF){ 205 if(n == -1) break; 206 tot = 1; 207 p[1].x = 0.0;p[1].y = 5.0;p[1].pos = 0; 208 double x,y[5]; 209 for(int i = 1;i <= n;i++){ 210 scanf("%lf",&x); 211 for(int j = 1;j <= 4;j++) { 212 ++tot; 213 scanf("%lf",&y[j]); 214 p[tot].x = x;p[tot].y = y[j];p[tot].pos = i; 215 line[i].y[j] = y[j]; 216 } 217 line[i].x = x; 218 } 219 ++tot;p[tot].x = 10;p[tot].y = 5;p[tot].pos = n+1; 220 solve(); 221 } 222 return 0; 223 }
8.23
poj 1410 Intersection
给出一个线段,再给出 一个矩形,判断线段是否 和 矩形相交
两个坑点
线段在矩形内部 也算 相交..
想到14年广州那道题,小矩形套在大矩形里面的时候,就只算大矩形的周长了..当时wa了一天..想哭了
然后,,题目明明说了 是给出 矩形的左上 和右下 的坐标,可是还要手动交换 下看是不是左上和右下的坐标..sigh
燃烧生命wa水题TwT/....
1 #include <cstdio> 2 #include <algorithm> 3 #include <cmath> 4 #include <vector> 5 using namespace std; 6 //lrj计算几何模板 7 struct Point 8 { 9 double x, y; 10 Point(double x=0, double y=0) :x(x),y(y) {} 11 }; 12 typedef Point Vector; 13 14 Point read_point(void) 15 { 16 double x, y; 17 scanf("%lf%lf", &x, &y); 18 return Point(x, y); 19 } 20 21 const double EPS = 1e-10; 22 23 //向量+向量=向量 点+向量=点 24 Vector operator + (Vector A, Vector B) { return Vector(A.x + B.x, A.y + B.y); } 25 26 //向量-向量=向量 点-点=向量 27 Vector operator - (Vector A, Vector B) { return Vector(A.x - B.x, A.y - B.y); } 28 29 //向量*数=向量 30 Vector operator * (Vector A, double p) { return Vector(A.x*p, A.y*p); } 31 32 //向量/数=向量 33 Vector operator / (Vector A, double p) { return Vector(A.x/p, A.y/p); } 34 35 bool operator < (const Point& a, const Point& b) 36 { return a.x < b.x || (a.x == b.x && a.y < b.y); } 37 38 int dcmp(double x) 39 { if(fabs(x) < EPS) return 0; else return x < 0 ? -1 : 1; } 40 41 bool operator == (const Point& a, const Point& b) 42 { return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0; } 43 44 /**********************基本运算**********************/ 45 46 //点积 47 double Dot(Vector A, Vector B) 48 { return A.x*B.x + A.y*B.y; } 49 //向量的模 50 double Length(Vector A) { return sqrt(Dot(A, A)); } 51 52 //向量的夹角,返回值为弧度 53 double Angle(Vector A, Vector B) 54 { return acos(Dot(A, B) / Length(A) / Length(B)); } 55 56 //叉积 57 double Cross(Vector A, Vector B) 58 { return A.x*B.y - A.y*B.x; } 59 60 //向量AB叉乘AC的有向面积 61 double Area2(Point A, Point B, Point C) 62 { return Cross(B-A, C-A); } 63 64 //向量A旋转rad弧度 65 Vector VRotate(Vector A, double rad) 66 { 67 return Vector(A.x*cos(rad) - A.y*sin(rad), A.x*sin(rad) + A.y*cos(rad)); 68 } 69 70 //将B点绕A点旋转rad弧度 71 Point PRotate(Point A, Point B, double rad) 72 { 73 return A + VRotate(B-A, rad); 74 } 75 76 //求向量A向左旋转90°的单位法向量,调用前确保A不是零向量 77 Vector Normal(Vector A) 78 { 79 double l = Length(A); 80 return Vector(-A.y/l, A.x/l); 81 } 82 83 /**********************点和直线**********************/ 84 85 //求直线P + tv 和 Q + tw的交点,调用前要确保两条直线有唯一交点 86 Point GetLineIntersection(Point P, Vector v, Point Q, Vector w) 87 { 88 Vector u = P - Q; 89 double t = Cross(w, u) / Cross(v, w); 90 return P + v*t; 91 }//在精度要求极高的情况下,可以自定义分数类 92 93 //P点到直线AB的距离 94 double DistanceToLine(Point P, Point A, Point B) 95 { 96 Vector v1 = B - A, v2 = P - A; 97 return fabs(Cross(v1, v2)) / Length(v1); //不加绝对值是有向距离 98 } 99 100 //点到线段的距离 101 double DistanceToSegment(Point P, Point A, Point B) 102 { 103 if(A == B) return Length(P - A); 104 Vector v1 = B - A, v2 = P - A, v3 = P - B; 105 if(dcmp(Dot(v1, v2)) < 0) return Length(v2); 106 else if(dcmp(Dot(v1, v3)) > 0) return Length(v3); 107 else return fabs(Cross(v1, v2)) / Length(v1); 108 } 109 110 //点在直线上的射影 111 Point GetLineProjection(Point P, Point A, Point B) 112 { 113 Vector v = B - A; 114 return A + v * (Dot(v, P - A) / Dot(v, v)); 115 } 116 117 //线段“规范”相交判定 118 bool SegmentProperIntersection(Point a1, Point a2, Point b1, Point b2) 119 { 120 double c1 = Cross(a2-a1, b1-a1), c2 = Cross(a2-a1, b2-a1); 121 double c3 = Cross(b2-b1, a1-b1), c4 = Cross(b2-b1, a2-b1); 122 return dcmp(c1)*dcmp(c2)<0 && dcmp(c3)*dcmp(c4)<0; 123 } 124 125 //判断点是否在线段上 126 bool OnSegment(Point P, Point a1, Point a2) 127 { 128 Vector v1 = a1 - P, v2 = a2 - P; 129 return dcmp(Cross(v1, v2)) == 0 && dcmp(Dot(v1, v2)) < 0; 130 } 131 132 //求多边形面积 133 double PolygonArea(Point* P, int n) 134 { 135 double ans = 0.0; 136 for(int i = 1; i < n - 1; ++i) 137 ans += Cross(P[i]-P[0], P[i+1]-P[0]); 138 return ans/2; 139 } 140 141 Point p[5],A,B; 142 143 int in(Point o){ 144 return o.x >= p[1].x && o.x <= p[3].x && o.y <= p[1].y && o.y >= p[3].y; 145 } 146 147 void solve(){ 148 if(in(A) && in(B)){ 149 puts("T"); 150 return; 151 } 152 for(int i = 1;i <= 4;i++){ 153 if(OnSegment(p[i],A,B)){ 154 puts("T"); 155 return; 156 } 157 } 158 for(int i = 1;i <= 4;i++){ 159 int v = (i+1); 160 if(v == 5) v = 1; 161 if(SegmentProperIntersection(A,B,p[i],p[v])){ 162 puts("T"); 163 return; 164 } 165 } 166 puts("F"); 167 } 168 169 int main(){ 170 int T; 171 scanf("%d",&T); 172 while(T--){ 173 scanf("%lf %lf %lf %lf",&A.x,&A.y,&B.x,&B.y); 174 double x1,x2,y1,y2,mn,mx; 175 scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2); 176 mn = min(x1,x2);mx = max(x1,x2); 177 x1 = mn;x2 = mx; 178 mn = min(y1,y2);mx = max(y1,y2); 179 y1 = mx;y2 = mn; 180 p[1].x = x1;p[1].y = y1; 181 p[2].x = x1;p[2].y = y2; 182 p[3].x = x2;p[3].y = y2; 183 p[4].x = x2;p[4].y = y1; 184 solve(); 185 } 186 return 0; 187 }
poj 1066 Treasure Hunt
给出 一个正方形,里面有 n 个墙,宝藏的位置 (x,y)
问从墙上任意一点 到达宝藏 至少需要炸掉 多少个墙(包括最边界的一个墙)
枚举每个端点,算这个端点 和宝藏连起来的线段 和多少个墙相交..
这里也是 线段严格相交的板
还有 就是 n = 0的时候,仍然需要炸掉边界上的墙,所以要输出 1
1 #include <cstdio> 2 #include <algorithm> 3 #include <cmath> 4 #include <vector> 5 using namespace std; 6 //lrj计算几何模板 7 8 const int INF = (1<<30)-1; 9 10 struct Point 11 { 12 double x, y; 13 Point(double x=0, double y=0) :x(x),y(y) {} 14 }; 15 16 struct Line{ 17 Point s,e; 18 Line(){} 19 Line(Point _s,Point _e){ 20 s = _s;e = _e; 21 } 22 }; 23 24 typedef Point Vector; 25 26 Point read_point(void) 27 { 28 double x, y; 29 scanf("%lf%lf", &x, &y); 30 return Point(x, y); 31 } 32 33 const double EPS = 1e-10; 34 35 //向量+向量=向量 点+向量=点 36 Vector operator + (Vector A, Vector B) { return Vector(A.x + B.x, A.y + B.y); } 37 38 //向量-向量=向量 点-点=向量 39 Vector operator - (Vector A, Vector B) { return Vector(A.x - B.x, A.y - B.y); } 40 41 //向量*数=向量 42 Vector operator * (Vector A, double p) { return Vector(A.x*p, A.y*p); } 43 44 //向量/数=向量 45 Vector operator / (Vector A, double p) { return Vector(A.x/p, A.y/p); } 46 47 bool operator < (const Point& a, const Point& b) 48 { return a.x < b.x || (a.x == b.x && a.y < b.y); } 49 50 int dcmp(double x) 51 { if(fabs(x) < EPS) return 0; else return x < 0 ? -1 : 1; } 52 53 bool operator == (const Point& a, const Point& b) 54 { return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0; } 55 56 /**********************基本运算**********************/ 57 58 //点积 59 double Dot(Vector A, Vector B) 60 { return A.x*B.x + A.y*B.y; } 61 //向量的模 62 double Length(Vector A) { return sqrt(Dot(A, A)); } 63 64 //向量的夹角,返回值为弧度 65 double Angle(Vector A, Vector B) 66 { return acos(Dot(A, B) / Length(A) / Length(B)); } 67 68 //叉积 69 double Cross(Vector A, Vector B) 70 { return A.x*B.y - A.y*B.x; } 71 72 //向量AB叉乘AC的有向面积 73 double Area2(Point A, Point B, Point C) 74 { return Cross(B-A, C-A); } 75 76 //向量A旋转rad弧度 77 Vector VRotate(Vector A, double rad) 78 { 79 return Vector(A.x*cos(rad) - A.y*sin(rad), A.x*sin(rad) + A.y*cos(rad)); 80 } 81 82 //将B点绕A点旋转rad弧度 83 Point PRotate(Point A, Point B, double rad) 84 { 85 return A + VRotate(B-A, rad); 86 } 87 88 //求向量A向左旋转90°的单位法向量,调用前确保A不是零向量 89 Vector Normal(Vector A) 90 { 91 double l = Length(A); 92 return Vector(-A.y/l, A.x/l); 93 } 94 95 /**********************点和直线**********************/ 96 97 //求直线P + tv 和 Q + tw的交点,调用前要确保两条直线有唯一交点 98 Point GetLineIntersection(Point P, Vector v, Point Q, Vector w) 99 { 100 Vector u = P - Q; 101 double t = Cross(w, u) / Cross(v, w); 102 return P + v*t; 103 }//在精度要求极高的情况下,可以自定义分数类 104 105 //P点到直线AB的距离 106 double DistanceToLine(Point P, Point A, Point B) 107 { 108 Vector v1 = B - A, v2 = P - A; 109 return fabs(Cross(v1, v2)) / Length(v1); //不加绝对值是有向距离 110 } 111 112 //点到线段的距离 113 double DistanceToSegment(Point P, Point A, Point B) 114 { 115 if(A == B) return Length(P - A); 116 Vector v1 = B - A, v2 = P - A, v3 = P - B; 117 if(dcmp(Dot(v1, v2)) < 0) return Length(v2); 118 else if(dcmp(Dot(v1, v3)) > 0) return Length(v3); 119 else return fabs(Cross(v1, v2)) / Length(v1); 120 } 121 122 //点在直线上的射影 123 Point GetLineProjection(Point P, Point A, Point B) 124 { 125 Vector v = B - A; 126 return A + v * (Dot(v, P - A) / Dot(v, v)); 127 } 128 129 //线段“规范”相交判定 130 bool SegmentProperIntersection(Point a1, Point a2, Point b1, Point b2) 131 { 132 double c1 = Cross(a2-a1, b1-a1), c2 = Cross(a2-a1, b2-a1); 133 double c3 = Cross(b2-b1, a1-b1), c4 = Cross(b2-b1, a2-b1); 134 return dcmp(c1)*dcmp(c2)<0 && dcmp(c3)*dcmp(c4)<0; 135 } 136 137 //判断点是否在线段上 138 bool OnSegment(Point P, Point a1, Point a2) 139 { 140 Vector v1 = a1 - P, v2 = a2 - P; 141 return dcmp(Cross(v1, v2)) == 0 && dcmp(Dot(v1, v2)) < 0; 142 } 143 144 //求多边形面积 145 double PolygonArea(Point* P, int n) 146 { 147 double ans = 0.0; 148 for(int i = 1; i < n - 1; ++i) 149 ans += Cross(P[i]-P[0], P[i+1]-P[0]); 150 return ans/2; 151 } 152 153 Point p[1005],A; 154 Line line[1005]; 155 int n,tot; 156 157 void solve(){ 158 int ans = INF; 159 for(int i = 1;i <= tot;i++){ 160 int cnt = 0; 161 for(int j = 1;j <= n;j++){ 162 if(SegmentProperIntersection(A,p[i],line[j].s,line[j].e)) cnt++; 163 } 164 ans = min(ans,cnt); 165 } 166 if(n == 0) ans = 1; 167 else ans++; 168 printf("Number of doors = %d\n",ans); 169 } 170 171 int main(){ 172 scanf("%d",&n); 173 tot = 0; 174 double x1,x2,y1,y2; 175 for(int i = 1;i <= n;i++){ 176 scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2); 177 p[++tot] = Point(x1,y1); 178 p[++tot] = Point(x2,y2); 179 line[i] = Line(Point(x1,y1),Point(x2,y2)); 180 } 181 A = read_point(); 182 solve(); 183 return 0; 184 }
8.24
给出 k 个链
有两个操作,一个是将 第 x 条链上的值反转(有变没,没变有)
另一个是询问 (x1,y1,x2,y2) 这个矩阵的和
直接暴力二维树状数组的,差 84ms T掉..姿势太挫了..
一会儿滚去学下别人的姿势
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <algorithm> 5 #include <vector> 6 #include <set> 7 using namespace std; 8 typedef long long LL; 9 const int maxn = 2e3+5; 10 11 int n,m,k,q; 12 LL c[maxn][maxn]; 13 vector<pair<pair<int,int>,int> > g[maxn]; 14 int tag[maxn],vis[maxn]; 15 16 int lowbit(int x){return x & (-x);} 17 18 LL sum(int x,int y){ 19 LL ret = 0LL; 20 int y1; 21 while(x){ 22 y1 = y; 23 while(y1){ 24 ret += c[x][y1];y1 -= lowbit(y1); 25 } 26 x -= lowbit(x); 27 } 28 return ret; 29 } 30 31 void update(int x,int y,int d){ 32 int y1; 33 while(x < maxn){ 34 y1 = y; 35 while(y1 < maxn){ 36 c[x][y1] += d;y1 += lowbit(y1); 37 } 38 x += lowbit(x); 39 } 40 } 41 42 void solve(){ 43 char cmd[10]; 44 int x1,x2,y1,y2; 45 scanf("%d",&q); 46 set<int> s; 47 LL ans = 0LL; 48 memset(tag,0,sizeof(tag)); 49 for(int i = 1;i <= q;i++){ 50 cin >> cmd; 51 if(cmd[0] == 'S'){ 52 scanf("%d",&x1); 53 tag[x1] = !tag[x1]; 54 } 55 else{ 56 for(int j = 1;j <= k;j++){ 57 if(tag[j] == vis[j]) continue; 58 for(int z = 0;z < g[j].size();z++){ 59 int u = g[j][z].first.first; 60 int v = g[j][z].first.second; 61 int w = g[j][z].second; 62 if(tag[j]) update(u,v,-w); 63 else update(u,v,w); 64 } 65 vis[j] = tag[j]; 66 } 67 scanf("%d %d %d %d",&x1,&y1,&x2,&y2); 68 ans = sum(x2,y2) + sum(x1-1,y1-1) - sum(x1-1,y2) - sum(x2,y1-1); 69 printf("%I64d\n",ans); 70 } 71 } 72 } 73 74 int main(){ 75 while(scanf("%d %d %d",&n,&m,&k) != EOF){ 76 memset(c,0,sizeof(c)); 77 for(int i = 1;i <= k;i++) g[i].clear(); 78 for(int i = 1;i <= k;i++){ 79 int num; 80 scanf("%d",&num); 81 int u,v,w; 82 for(int j = 1;j <= num;j++){ 83 scanf("%d %d %d",&u,&v,&w); 84 g[i].push_back(make_pair(make_pair(u,v),w)); 85 // update(u,v,w); 86 } 87 vis[i] = 1; 88 } 89 solve(); 90 } 91 return 0; 92 }
8.25
什么都没干
8.26
接着写几何..
poj 1696 Space Ant
每次排序 找最左边的点
不知道为什么平时用的板 一直 wa
kuangbin板就可以
唉
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <cmath> 5 #include <vector> 6 using namespace std; 7 //lrj计算几何模板 8 9 const double eps = 1e-8; 10 11 struct Point 12 { 13 double x,y; 14 int id; 15 Point(){} 16 Point(double _x,double _y) 17 { 18 x = _x;y = _y; 19 } 20 Point operator -(const Point &b)const 21 { 22 return Point(x - b.x,y - b.y); 23 } 24 //叉积 25 double operator ^(const Point &b)const 26 { 27 return x*b.y - y*b.x; 28 } 29 //点积 30 double operator *(const Point &b)const 31 { 32 return x*b.x + y*b.y; 33 } 34 }; 35 //*两点间距离 36 double dist(Point a,Point b){ 37 return sqrt((a-b)*(a-b)); 38 } 39 40 int dcmp(double x){ 41 if(fabs(x) < eps)return 0; 42 if(x < 0)return -1; 43 else return 1; 44 } 45 46 Point p[105]; 47 int n,pos; 48 49 bool cmp1(Point a,Point b){ 50 double tmp = (a-p[pos])^(b-p[pos]); 51 if(dcmp(tmp) == 0) 52 return dist(p[pos],a) < dist(p[pos],b); 53 else if(dcmp(tmp) < 0)return false; 54 else return true; 55 } 56 57 void solve(){ 58 for(int i = 0;i < n;i++){ 59 if(p[i].y < p[0].y || (p[i].y == p[0].y && p[i].x < p[0].x)) swap(p[0],p[i]); 60 } 61 // printf("p[0].id = %d x = %lf y = %lf\n",p[0].id,p[0].x,p[0].y); 62 pos = 0; 63 for(int i = 1;i < n;i++){ 64 sort(p+i,p+n,cmp1); 65 pos++; 66 } 67 68 printf("%d",n); 69 for(int i = 0;i < n;i++) printf(" %d",p[i].id); 70 printf("\n"); 71 } 72 73 int main(){ 74 int T; 75 scanf("%d",&T); 76 while(T--){ 77 scanf("%d",&n); 78 for(int i = 0;i < n;i++){ 79 scanf("%d%lf%lf",&p[i].id,&p[i].x,&p[i].y); 80 } 81 /* for(int i = 0;i < n;i++){ 82 printf("p[%d].id = %d x = %lf y = %lf\n",i,p[i].id,p[i].x,p[i].y); 83 }*/ 84 solve(); 85 } 86 return 0; 87 }