8.12
This commit is contained in:
parent
4beb69ee8a
commit
349b318ffd
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"algorithm": "cpp"
|
||||
}
|
||||
}
|
@ -1,105 +0,0 @@
|
||||
//weiwancheng
|
||||
#include<iostream>
|
||||
#include<cstdio>
|
||||
#include<cmath>
|
||||
#include<cstring>
|
||||
using namespace std;
|
||||
const double inf=1e100,EPS=1e-6;
|
||||
const int N=101;
|
||||
double l,now;
|
||||
int n;
|
||||
struct edge
|
||||
{
|
||||
double x[2],y[2];
|
||||
} e[N];
|
||||
//big bug:double->int
|
||||
double length(double x1,double y1,double x2,double y2)
|
||||
{
|
||||
double x=x1-x2,y=y1-y2;
|
||||
return sqrt(x*x+y*y);
|
||||
}
|
||||
double cross(double x1,double y1,double x2,double y2)
|
||||
{
|
||||
return x1*y2-x2*y1;
|
||||
}
|
||||
double same(double x0,double y0,double x3,double y3,double x1,double y1,double x2,double y2)
|
||||
{
|
||||
double x=x3-x0,y=y3-y0;//y0->x0
|
||||
return cross(x,y,x1-x0,y1-y0)*cross(x,y,x2-x0,y2-y0);
|
||||
}
|
||||
//WA double 判断正负要用
|
||||
int sign(double d)
|
||||
{
|
||||
if(fabs(d)<EPS)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else return d>0? 1:-1;
|
||||
}
|
||||
bool ob(int li,int lj,int ri,int rj)
|
||||
{
|
||||
for(int i=li+1; i<ri; i++)
|
||||
{
|
||||
for(int j=0; j<=4; j+=2)
|
||||
{
|
||||
// printf("(%.0lf,%.0lf)(%.0lf,%.0lf)/(%.0lf,%.0lf)(%.0lf,%.0lf):",w[i].x,w[i].y[j],w[i].x,w[i].y[j+1],w[li].x,w[li].y[lj],w[ri].x,w[ri].y[rj]);
|
||||
// printf("[%.2lf/%.2lf]\n",same(w[i].x,w[i].y[j],w[i].x,w[i].y[j+1],w[li].x,w[li].y[lj],w[ri].x,w[ri].y[rj]),same(w[li].x,w[li].y[lj],w[ri].x,w[ri].y[rj],w[i].x,w[i].y[j],w[i].x,w[i].y[j+1]));
|
||||
//两个都同方向才是,应该&&,错以为|| ,不是0都是真 两个小于0才是香蕉
|
||||
if(sign(same(w[i].x,w[i].y[j],w[i].x,w[i].y[j+1],w[li].x,w[li].y[lj],w[ri].x,w[ri].y[rj]))<0&&sign(same(w[li].x,w[li].y[lj],w[ri].x,w[ri].y[rj],w[i].x,w[i].y[j],w[i].x,w[i].y[j+1]))<0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
void find(int ii,int jj)
|
||||
{
|
||||
for(int i=0; i<ii; i++)
|
||||
{
|
||||
for(int j=1; j<=4; j++)
|
||||
{
|
||||
l=length(w[ii].x,w[ii].y[jj],w[i].x,w[i].y[j]);
|
||||
now=w[i].val[j]+l;//i j ii,jj搞反了
|
||||
if(now<w[ii].val[jj]&&ob(i,j,ii,jj))
|
||||
{
|
||||
w[ii].val[jj]=now;
|
||||
}
|
||||
// printf("(%.0lf,%.0lf)(%.0lf,%.0lf):length:%.3lf,now:%.3lf,val:%.3lf\n",w[ii].x,w[ii].y[jj],w[i].x,w[i].y[j],l,now,w[ii].val[jj]);
|
||||
if(i==0) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
void doit()
|
||||
{
|
||||
for(int i=1; i<=n; i++)
|
||||
{
|
||||
for(int j=1; j<=4; j++)
|
||||
{
|
||||
find(i,j);
|
||||
if(i==n) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
int main()
|
||||
{
|
||||
scanf("%d",&t);
|
||||
while(t--)
|
||||
{
|
||||
scanf("%d",&n);
|
||||
memset(&e,0,sizeof(edge)*(n+1));
|
||||
for(int i=1; i<=n; i++)
|
||||
{
|
||||
for(int j=0; j<2; j++)// 又是j
|
||||
{
|
||||
scanf("%lf",&e[i].x[j],&e[i].y[j]);
|
||||
}
|
||||
}
|
||||
w[++n].x=10;
|
||||
w[n].y[1]=5;
|
||||
w[n].val[1]=inf;// bug 没赋值
|
||||
doit();
|
||||
printf("%.2lf\n",w[n].val[1]);
|
||||
}
|
||||
|
||||
}
|
108
8.10/C-edge/C-edge.cpp
Normal file
108
8.10/C-edge/C-edge.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
const double inf = 1e100, EPS = 1e-8;
|
||||
const int N = 101;
|
||||
double l, now;
|
||||
int n,t;
|
||||
struct edge
|
||||
{
|
||||
double x[2], y[2];
|
||||
} e[N];
|
||||
// WA double 判断正负要用
|
||||
int sign(double d)
|
||||
{
|
||||
if (fabs(d) < EPS)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return d > 0 ? 1 : -1;
|
||||
}
|
||||
double cross(double x1, double y1, double x2, double y2)
|
||||
{
|
||||
return x1 * y2 - x2 * y1;
|
||||
}
|
||||
int same(double x0, double y0, double x3, double y3, double x1, double y1, double x2, double y2)
|
||||
{
|
||||
double x = x3 - x0, y = y3 - y0; // y0->x0
|
||||
//WA? 没有用浮点数的大小比较方法
|
||||
return sign(cross(x, y, x1 - x0, y1 - y0)) * sign(cross(x, y, x2 - x0, y2 - y0));
|
||||
}
|
||||
//与所有边比是否相交
|
||||
bool ob(int x0, int y0, int x1, int y1)
|
||||
{
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
if (sign(same(x0,y0,x1,y1,e[i].x[0],e[i].y[0],e[i].x[1],e[i].y[1])) > 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
//另一线段的点,连点成线
|
||||
bool dot2(int ii, int jj)
|
||||
{
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
if (i == ii)
|
||||
continue;
|
||||
for (int j = 0; j < 2; j++)
|
||||
{
|
||||
if(sign(e[ii].x[jj]-e[i].x[j])==0&&sign(e[ii].y[jj]-e[i].y[j])==0) continue;
|
||||
if (ob(e[ii].x[jj], e[ii].y[jj], e[i].x[j], e[i].y[j]))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
//找一个点
|
||||
bool adot()
|
||||
{
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
for (int j = 0; j < 2; j++)
|
||||
{
|
||||
if (dot2(i, j))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
scanf("%d", &t);
|
||||
while (t--)
|
||||
{
|
||||
scanf("%d", &n);
|
||||
memset(&e, 0, sizeof(edge) * (n + 1));
|
||||
for (int i = 1; i <= n; i++)
|
||||
{
|
||||
for (int j = 0; j < 2; j++) // 又是j
|
||||
{
|
||||
scanf("%lf%lf", &e[i].x[j], &e[i].y[j]);//少一个%lf
|
||||
}
|
||||
}
|
||||
if(n==1)
|
||||
{
|
||||
printf("Yes!\n");
|
||||
continue;
|
||||
}
|
||||
if(adot())
|
||||
{
|
||||
printf("Yes!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("No!\n");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
3
8.10/C-edge/Readme.md
Normal file
3
8.10/C-edge/Readme.md
Normal file
@ -0,0 +1,3 @@
|
||||
# 标题
|
||||
|
||||
* 内容
|
8
8.10/C-edge/ce.cpp
Normal file
8
8.10/C-edge/ce.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
#include <iostream>
|
||||
#include<cstdio>
|
||||
int main()
|
||||
{
|
||||
|
||||
printf("%.0lf",1.4);
|
||||
return 0;
|
||||
}
|
1
8.10/C-edge/doc/Readme.md
Normal file
1
8.10/C-edge/doc/Readme.md
Normal file
@ -0,0 +1 @@
|
||||
#
|
6
8.10/C-edge/main.cpp
Normal file
6
8.10/C-edge/main.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int main()
|
||||
{
|
||||
|
||||
}
|
0
8.10/C-edge/test/in.txt
Normal file
0
8.10/C-edge/test/in.txt
Normal file
12
8.10/C-edge/test/in2.txt
Normal file
12
8.10/C-edge/test/in2.txt
Normal file
@ -0,0 +1,12 @@
|
||||
3
|
||||
2
|
||||
1.0 2.0 3.0 4.0
|
||||
4.0 5.0 6.0 7.0
|
||||
3
|
||||
0.0 0.0 0.0 1.0
|
||||
0.0 1.0 0.0 2.0
|
||||
1.0 1.0 2.0 1.0
|
||||
3
|
||||
0.0 0.0 0.0 1.0
|
||||
0.0 2.0 0.0 3.0
|
||||
1.0 1.0 2.0 1.0
|
0
8.10/C-edge/test/in3.txt
Normal file
0
8.10/C-edge/test/in3.txt
Normal file
7
8.10/C-edge/test/out.txt
Normal file
7
8.10/C-edge/test/out.txt
Normal file
@ -0,0 +1,7 @@
|
||||
## z:\Chao\src\Template\test\in.txt
|
||||
2020/03/14 ÖÜÁù 11:41:28.68
|
||||
Hello Easy C++ project!
|
||||
|
||||
-----------------------------------------------
|
||||
Process exited after 200 ms with return value 0
|
||||
|
3
8.10/I-Wall/Readme.md
Normal file
3
8.10/I-Wall/Readme.md
Normal file
@ -0,0 +1,3 @@
|
||||
# 标题
|
||||
|
||||
* 内容
|
2
8.10/I-Wall/doc/Readme.md
Normal file
2
8.10/I-Wall/doc/Readme.md
Normal file
@ -0,0 +1,2 @@
|
||||
# 攷관
|
||||
*https://www.cnblogs.com/aiguona/p/7232243.html
|
65
8.10/I-Wall/main.cpp
Normal file
65
8.10/I-Wall/main.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <algorithm>
|
||||
#include<stack>
|
||||
using namespace std;
|
||||
const double pi=acos(-1.00),eps = 1e-6;//pi3.14~
|
||||
const int N=1001,inf=0x3f3f3f3f;
|
||||
double ans=0;
|
||||
struct dot{
|
||||
int x,y;
|
||||
}d[N];
|
||||
stack<int>s;
|
||||
int sign(double d)
|
||||
{
|
||||
if(fabs(d)<eps) return 0;
|
||||
return d>0? 1:-1;
|
||||
}
|
||||
double cross(double x1, double y1, double x2, double y2)
|
||||
{
|
||||
return x1 * y2 - x2 * y1;
|
||||
}
|
||||
double length(int x1,int y1,int x2,int y2)
|
||||
{
|
||||
int x=x1-x2,y=y1-y2;
|
||||
return sqrt((double)x*x+y*y);//CE double
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int n,l,minn=1,f,ff,x0,x1,x2,y1,y2,y0;
|
||||
scanf("%d%d",&n,&l);
|
||||
for(int i=1;i<=n;i++)
|
||||
{
|
||||
scanf("%d%d",&d[i].x,&d[i].y);//&!!!
|
||||
minn=d[i].y<d[minn].y? i:minn;
|
||||
}
|
||||
int j=(n+minn-2)%n+1;
|
||||
// s.push(minn%n+1);
|
||||
s.push(minn);
|
||||
s.push(j);
|
||||
ans+=length(d[j].x,d[j].y,d[minn].x,d[minn].y);//漏了初始的边
|
||||
while(j!=minn)
|
||||
{
|
||||
j=(j+n-2)%n+1;
|
||||
f=s.top();
|
||||
s.pop();
|
||||
ff=s.top();
|
||||
while(0>=sign(cross(d[f].x-d[ff].x,d[f].y-d[ff].y,d[j].x-d[ff].x,d[j].y-d[ff].y)))
|
||||
{
|
||||
ans-=length(d[f].x,d[f].y,d[ff].x,d[ff].y);
|
||||
// printf("--%d(%d,%d),%d(%d,%d): -%lf=%lf\n",f,d[f].x,d[f].y,ff,d[ff].x,d[ff].y,length(d[f].x,d[f].y,d[ff].x,d[ff].y),ans);
|
||||
f=s.top();
|
||||
s.pop();
|
||||
if(s.empty()) break;//RE
|
||||
ff=s.top();
|
||||
}
|
||||
ans+=length(d[j].x,d[j].y,d[f].x,d[f].y);
|
||||
// printf("++%d(%d,%d),%d(%d,%d): +%lf=%lf\n",j,d[j].x,d[j].y,f,d[f].x,d[f].y,length(d[j].x,d[j].y,d[f].x,d[f].y),ans);
|
||||
s.push(f);
|
||||
s.push(j);
|
||||
}
|
||||
// printf("%d ",s.size());
|
||||
printf("%.0lf",ans+2*l*pi);//WA*2 (周长跟多边形形状有关)错了,无关,自带四舍五入
|
||||
return 0;
|
||||
}
|
0
8.10/I-Wall/test/in.txt
Normal file
0
8.10/I-Wall/test/in.txt
Normal file
0
8.10/I-Wall/test/in2.txt
Normal file
0
8.10/I-Wall/test/in2.txt
Normal file
0
8.10/I-Wall/test/in3.txt
Normal file
0
8.10/I-Wall/test/in3.txt
Normal file
7
8.10/I-Wall/test/out.txt
Normal file
7
8.10/I-Wall/test/out.txt
Normal file
@ -0,0 +1,7 @@
|
||||
## z:\Chao\src\Template\test\in.txt
|
||||
2020/03/14 ÖÜÁù 11:41:28.68
|
||||
Hello Easy C++ project!
|
||||
|
||||
-----------------------------------------------
|
||||
Process exited after 200 ms with return value 0
|
||||
|
60
8.10/I-Wall/标程.cpp
Normal file
60
8.10/I-Wall/标程.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
using namespace std;
|
||||
const int N = 1e3 + 5;
|
||||
const double PI = acos(-1.0), eps = 1e-8;
|
||||
struct Point {
|
||||
double x, y;
|
||||
Point () {}
|
||||
Point (double xx, double yy) : x(xx), y(yy) {}
|
||||
Point friend operator - (Point a, Point b) {
|
||||
return Point(a.x - b.x, a.y - b.y);
|
||||
}
|
||||
double friend operator ^ (Point a, Point b) {
|
||||
return a.x * b.y - b.x * a.y;
|
||||
}
|
||||
bool friend operator < (Point a, Point b) {
|
||||
if (a.y == b.y) return a.x < b.x;
|
||||
return a.y < b.y;
|
||||
}
|
||||
} p[N];
|
||||
int n, L, q[N];
|
||||
double dist (Point a, Point b){
|
||||
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
|
||||
}
|
||||
int Sign(double x) {
|
||||
if (x >= -eps && x <= eps) return 0;
|
||||
return x > eps ? 1 : -1;
|
||||
}
|
||||
bool cmp(Point a, Point b) {
|
||||
int s = Sign((a - p[1]) ^ (b - p[1]));
|
||||
if(s > 0 || (s == 0 && dist(a, p[1]) < dist(b, p[1]))) return 1;
|
||||
else return 0;
|
||||
}
|
||||
double Graham() {
|
||||
sort(p + 1, p + n + 1);
|
||||
sort(p + 1, p + n + 1, cmp);
|
||||
int top = 3;
|
||||
q[1] = 1, q[2] = 2, q[3] = 3;
|
||||
for (int i = 4; i <= n; i++) {
|
||||
while(top > 1 && Sign((p[q[top]] - p[q[top - 1]]) ^ (p[i] - p[q[top]])) <= 0)
|
||||
top--;
|
||||
q[++top] = i;
|
||||
}
|
||||
double res = 0;
|
||||
for (int i = 1; i < top; i++)
|
||||
res += dist(p[q[i]], p[q[i + 1]]);
|
||||
res += dist(p[q[1]], p[q[top]]);
|
||||
res += 2.0 * PI * L;
|
||||
return res;
|
||||
}
|
||||
int main() {
|
||||
// freopen("1.txt", "r", stdin);
|
||||
scanf("%d %d", &n, &L);
|
||||
for (int i = 1; i <= n; i++)
|
||||
scanf("%lf %lf", &p[i].x, &p[i].y);
|
||||
printf("%d\n", (int)(Graham() + 0.5));
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user