其他分享
首页 > 其他分享> > Angle Beats Gym - 102361A

Angle Beats Gym - 102361A

作者:互联网

题目链接:https://vjudge.net/problem/Gym-102361A

题意:给定N个点,q次询问每次询问给一个点,问在N个点中取2个和给定点最多可以组成几个直角三角形。

思路:https://www.cnblogs.com/Jiaaaaaaaqi/p/11631203.html

  1 #include <bits/stdc++.h>
  2 #include <time.h>
  3 #include <set>
  4 #include <map>
  5 #include <stack>
  6 #include <cmath>
  7 #include <queue>
  8 #include <cstdio>
  9 #include <string>
 10 #include <vector>
 11 #include <cstring>
 12 #include <utility>
 13 #include <cstring>
 14 #include <iostream>
 15 #include <algorithm>
 16 #include <list>
 17 using namespace std;
 18 //cout<<setprecision(10)<<fixed;
 19 #define eps 1e-6
 20 #define PI acos(-1.0)
 21 #define lowbit(x) ((x)&(-x))
 22 #define zero(x) (((x)>0?(x):-(x))<eps)
 23 #define mem(s,n) memset(s,n,sizeof s);
 24 #define rep(i,a,b) for(int i=a;i<=b;i++)
 25 #define rep2(i,a,b) for(int i=a;i>=b;i--)
 26 #define ios {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
 27 typedef long long ll;
 28 typedef unsigned long long ull;
 29 const int maxn=1e6+5;
 30 const ll Inf=0x7f7f7f7f7f7f7f7f;
 31 const ll mod=1e6+3;
 32 //const int N=3e3+5;
 33 bool isPowerOfTwo(int n) { return n > 0 && (n & (n - 1)) == 0; }//判断一个数是不是 2 的正整数次幂
 34 int modPowerOfTwo(int x, int mod) { return x & (mod - 1); }//对 2 的非负整数次幂取模
 35 int getBit(int a, int b) { return (a >> b) & 1; }// 获取 a 的第 b 位,最低位编号为 0
 36 int Max(int a, int b) { return b & ((a - b) >> 31) | a & (~(a - b) >> 31); }// 如果 a>=b,(a-b)>>31 为 0,否则为 -1
 37 int Min(int a, int b) { return a & ((a - b) >> 31) | b & (~(a - b) >> 31); }
 38 ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
 39 ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
 40 inline int read()
 41 {
 42     int X=0; bool flag=1; char ch=getchar();
 43     while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
 44     while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
 45     if(flag) return X;
 46     return ~(X-1);
 47 }
 48 inline void write(int X)
 49 {
 50     if(X<0) {X=~(X-1); putchar('-');}
 51     if(X>9) write(X/10);
 52     putchar(X%10+'0');
 53 }
 54 /*
 55 inline int write(int X)
 56 {
 57     if(X<0) {putchar('-'); X=~(X-1);}
 58     int s[20],top=0;
 59     while(X) {s[++top]=X%10; X/=10;}
 60     if(!top) s[++top]=0;
 61     while(top) putchar(s[top--]+'0');
 62 }
 63 */
 64 int Abs(int n) {
 65   return (n ^ (n >> 31)) - (n >> 31);
 66   /* n>>31 取得 n 的符号,若 n 为正数,n>>31 等于 0,若 n 为负数,n>>31 等于 -1
 67      若 n 为正数 n^0=n, 数不变,若 n 为负数有 n^(-1)
 68      需要计算 n 和 -1 的补码,然后进行异或运算,
 69      结果 n 变号并且为 n 的绝对值减 1,再减去 -1 就是绝对值 */
 70 }
 71 ll binpow(ll a, ll b) {
 72   ll res = 1;
 73   while (b > 0) {
 74     if (b & 1) res = res * a%mod;
 75     a = a * a%mod;
 76     b >>= 1;
 77   }
 78   return res%mod;
 79 }
 80 void extend_gcd(ll a,ll b,ll &x,ll &y)
 81 {
 82     if(b==0) {
 83         x=1,y=0;
 84         return;
 85     }
 86     extend_gcd(b,a%b,x,y);
 87     ll tmp=x;
 88     x=y;
 89     y=tmp-(a/b)*y;
 90 }
 91 ll mod_inverse(ll a,ll m)
 92 {
 93     ll x,y;
 94     extend_gcd(a,m,x,y);
 95     return (m+x%m)%m;
 96 }
 97 ll eulor(ll x)
 98 {
 99    ll cnt=x;
100    ll ma=sqrt(x);
101    for(int i=2;i<=ma;i++)
102    {
103     if(x%i==0) cnt=cnt/i*(i-1);
104     while(x%i==0) x/=i;
105    }
106    if(x>1) cnt=cnt/x*(x-1);
107    return cnt;
108 }
109 struct node
110 {
111     ll x,y;
112     int id;
113 }p[maxn],be[maxn];
114 int n,m;
115 int ans[maxn];
116 int cmp1(node a,node b)
117 {
118     ll d=a.x*b.y-b.x*a.y;
119     if(d==0) return a.x<b.x;
120     else return d>0;
121 }
122 int qua(node a)
123 {
124     if(a.x>0&&a.y>=0) return 1;
125     else if(a.x<=0&&a.y>0) return 2;
126     else if(a.x<0&&a.y<=0) return 3;
127     else if(a.x>=0&&a.y<=0) return 4;
128 }
129 int cmp(node a,node b)
130 {
131     if(qua(a)==qua(b)) return cmp1(a,b);
132     else return qua(a)<qua(b);
133 }
134 ll check(node a,node b)
135 {
136     return a.x*b.x+a.y*b.y;
137 }
138 ll chaji(node a,node b)
139 {
140     return a.x*b.y-b.x*a.y;
141 }
142 ll work(node pp)
143 {
144     for(int i=1;i<=n;i++)
145     {
146         p[i]=be[i];
147         p[i].x-=pp.x;
148         p[i].y-=pp.y;
149     }
150     p[0]=pp;
151     sort(p+1,p+n+1,cmp);
152     for(int i=1;i<=n;i++)
153     {
154         p[i+n]=p[i];
155     }
156     ll ans=0;
157     int r=2;
158     for(int l=1;l<=n;l++)
159     {
160         while(r<=2*n)
161         {
162             if(chaji(p[l],p[r])<0) break;
163             if(check(p[l],p[r])<=0) break;
164             r++;
165         }
166         int tr=r;
167         while(tr<=2*n)
168         {
169             if(chaji(p[l],p[tr])<=0) break;
170             if(check(p[l],p[tr])!=0) break;
171             ans++;
172             tr++;
173         }
174     }
175     return ans;
176 }
177 int main()
178 {
179     while(~scanf("%d%d",&n,&m))
180     {
181         int all=0;
182         for(int i=1;i<=n;i++)
183         {
184             all++;
185             int x,y;
186             scanf("%d%d",&x,&y);
187             p[all].x=x,p[all].y=y,p[all].id=0;
188             be[all]=p[all];
189         }
190         for(int i=1;i<=m;i++)
191         {
192             all++;
193             int x,y;
194             scanf("%d%d",&x,&y);
195             p[all].x=x,p[all].y=y,p[all].id=i;
196             be[all]=p[all];
197             ans[i]=work(p[all]);
198         }
199         for(int i=1;i<=n;i++)
200         {
201             for(int j=1;j<=all;j++)
202             {
203                 p[j]=be[j];
204             }
205             p[0]=be[i];
206             int flag=0;
207             for(int j=1;j<=all;j++)
208             {
209                 if(p[j].x==p[0].x&&p[j].y==p[0].y) flag=1;
210                 if(flag) p[j]=p[j+1];
211                 p[j].x-=p[0].x;
212                 p[j].y-=p[0].y;
213             }
214             int nn=all-1;
215             sort(p+1,p+1+nn,cmp);
216             for(int j=1;j<=nn;j++)
217             {
218                 p[j+nn]=p[j];
219             }
220             int r=2;
221             for(int l=1;l<=nn;l++)
222             {
223                 int id=0;
224                 if(p[0].id) id=p[0].id;
225                 if(p[l].id) id=p[l].id;
226                 while(r<=2*nn)
227                 {
228                     if(chaji(p[l],p[r])<0) break;
229                     if(check(p[l],p[r])<=0) break;
230                     r++;
231                 }
232                 int tr=r;
233                 while(tr<=2*nn)
234                 {
235                     if(chaji(p[l],p[tr])<=0) break;
236                     if(check(p[l],p[tr])!=0) break;
237                     if(id==0)
238                     {
239                         if(p[tr].id) ans[p[tr].id]++;
240                     }
241                     else
242                     {
243                         if(p[tr].id==0) ans[id]++;
244                     }
245                     tr++;
246                 }
247             }
248         }
249         for(int i=1;i<=m;i++)
250         {
251             printf("%d\n",ans[i]);
252         }
253     }
254     return 0;
255 }

 

标签:Angle,int,ll,Beats,31,return,include,Gym,mod
来源: https://www.cnblogs.com/zpj61/p/13625227.html