-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhead.cpp
155 lines (154 loc) · 3.36 KB
/
head.cpp
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
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<ctime>
#include<vector>
#include<utility>
using namespace std;
#define INF (1<<30)
#define EPS 1e-6
#define PI acos(-1)
#define lowbit(x) ((x) & (-(x)))
#define IDX(l,r) ((l)+(r) | (l)!=(r))
#define ABS(x) ((x)>0?(x):-(x))
#define SET(a,b) memset(a,b,sizeof(a))
#define NN 40
#define MM 10010
int rands()
{
static int x=1364684679;
x+=(x<<2)+1;
return x;
}
struct point
{
double x,y;
int init(){return scanf("%lf%lf",&x,&y);}
point operator + (point a)
{ point ret; ret.x=x+a.x; ret.y=y+a.y; return ret; }
point operator - (point a)
{ point ret; ret.x=x-a.x; ret.y=y-a.y; return ret; }
double operator * (point a) { return x*a.y-y*a.x; }
double operator ^ (point a) { return x*a.x+y*a.y; }
};
struct circle{ point o; double r; };
struct point3
{
double x,y,z;
int init(){return scanf("%lf%lf%lf",&x,&y,&z);}
void output(){printf("%lf %lf %lf",x,y,z);}
point3 operator + (point3 a)
{ point3 ret; ret.x=x+a.x; ret.y=y+a.y; ret.z=z+a.z; return ret; }
point3 operator - (point3 a)
{ point3 ret; ret.x=x-a.x; ret.y=y-a.y; ret.z=z-a.z; return ret; }
point3 operator * (point3 a)
{
point3 ret;
ret.x=y*a.z-z*a.y; ret.y=z*a.x-x*a.z; ret.z=x*a.y-y*a.x;
return ret;
}
point3 operator * (double b)
{
point3 ret;
ret.x=x*b; ret.y=y*b; ret.z=z*b;
return ret;
}
double operator ^ (point3 a){ return x*a.x+y*a.y+z*a.z; }
double vlen(){ return sqrt(x*x+y*y+z*z); }
};
double xmult(point p0,point p1,point p2)
{ return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x); }
point3 xmult3(point3 p0,point3 p1,point3 p2)
{
point3 ret;
ret.x=(p1.y-p0.y)*(p2.z-p0.z)-(p1.z-p0.z)*(p2.y-p0.y);
ret.y=(p1.z-p0.z)*(p2.x-p0.x)-(p1.x-p0.x)*(p2.z-p0.z);
ret.z=(p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x);
return ret;
}
double dot(point a,point b){ return a.x*b.x+a.y*b.y; }
double dot3(point3 a,point3 b){ return a.x*b.x+a.y*b.y+a.z*b.z; }
double dist(point a,point b)
{ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); }
double dist3(point3 a,point3 b)
{ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z)); }
struct matrix
{
int n; int a[NN][NN];
void clear(){ memset(a,0,sizeof(a)); }
void init(){ clear(); for(int i=1;i<=n;i++) a[i][i]=1; }
matrix operator * (matrix b)
{
matrix c; c.n=n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
c.a[i][j]=0;
for(int k=1;k<=n;k++) c.a[i][j]+=a[i][k]*b.a[k][j];
}
return c;
}
matrix operator + (matrix b)
{
matrix c; c.n=n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
c.a[i][j]=a[i][j]+b.a[i][j];
return c;
}
void printmatrix()
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
printf("%d ",a[i][j]);
printf("\n");
}
}
};
int fastget()
{
char c; int ans=0; c=getchar();
int sign=1;
while (! (c>='0' && c<='9' || c=='-')) c=getchar();
if(c=='-') sign=-1,c=getchar();
while (c>='0' && c<='9')
{
ans=(ans<<3)+(ans<<1)+c-'0';
c=getchar();
}
return ans*sign;
}
void fastput(int x)
{
char s[12]; int a=0;
if(x==0) puts("0");
else
{
if(x<0) putchar('-'),x=-x;
while (x) { s[a++]=x%10+'0'; x/=10; }
for(a--;a>=0;a--) putchar(s[a]);
putchar('\n');
}
}
//a^b%p
int abp(int a,int b,int p)
{
int ans = 1;
while(b) {
if(b&1) {
ans = ans*a%p;
}
a = a*a%p;
b>>=1;
}
return ans;
}