CCPC秦皇岛gym102361A. Angle Beats
生活随笔
收集整理的這篇文章主要介紹了
CCPC秦皇岛gym102361A. Angle Beats
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
CCPC秦皇島gym102361A. Angle Beats
題意:
給你n個點的坐標,現在有q次詢問,每次詢問給你一個坐標,問這個坐標可以與給定的n個點組成多少個不同的直角三角形
n<=2000,q<=2000
題解:
正解貌似是用極角排序后尺取得到答案,但我看很多人有更簡便的方法
對于每次詢問,我們可以分別考慮被詢問點是直角點還是非直角點
如果是直角點,我們可以先將n個點與被詢問點的斜率存下來,然后再循環n個點,看有多少個點是可以構成直線(即斜率乘積為-1)
如果是非直角點,我們可以直接n2n^2n2枚舉n個點,然后判斷是否可以構成直角
這個題原理很簡單,細節很多,首先斜率直接存很麻煩,我們存橫縱坐標。其次map跑的很慢,因此加map的值時可以先判斷map中是否存有對應的參數,否則會T
詳細見代碼
代碼:
#include <bits/stdc++.h> #include <unordered_map> #define debug(a, b) printf("%s = %d\n", a, b); using namespace std; bool Handsome; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> PII; clock_t startTime, endTime; //Fe~Jozky const ll INF_ll= 1e18; const int INF_int= 0x3f3f3f3f; void read(){}; template <typename _Tp, typename... _Tps> void read(_Tp& x, _Tps&... Ar) {x= 0;char c= getchar();bool flag= 0;while (c < '0' || c > '9')flag|= (c == '-'), c= getchar();while (c >= '0' && c <= '9')x= (x << 3) + (x << 1) + (c ^ 48), c= getchar();if (flag)x= -x;read(Ar...); } template <typename T> inline void write(T x) {if (x < 0) {x= ~(x - 1);putchar('-');}if (x > 9)write(x / 10);putchar(x % 10 + '0'); } void rd_test(bool &Most) { #ifdef ONLINE_JUDGE #elseprintf("%.2lfMB\n",(&Most-&Handsome)/1024.0/1024.0);startTime = clock ();freopen("data.in", "r", stdin); #endif } void Time_test() { #ifdef ONLINE_JUDGE #elseendTime= clock();printf("\nRun Time:%lfs\n", (double)(endTime - startTime) / CLOCKS_PER_SEC); #endif } const int maxn=2e4+9; bool Most; struct Point{ll x,y;Point(){}Point(ll _x,ll _y){x=_x;y=_y;}void input(){read(x,y);}Point update()const{if(x<0||(x==0&&y<0))return Point(-x,-y);else return Point(x,y);}bool operator<(const Point &b)const{Point A=update(),B=b.update(); return A.x*B.y<A.y*B.x;}Point operator-(const Point &b)const{return Point(x-b.x,y-b.y); } }point[maxn]; int ans[maxn]; map<Point,int>mp; vector<Point>vec; int main() {rd_test(Most);int n,q;read(n,q);for(int i=1;i<=n;i++)point[i].input();for(int i=0;i<q;i++){mp.clear();Point q;q.input();vec.push_back(q);for(int j=1;j<=n;j++)mp[point[j]-q]++;for(auto it:mp){Point tmp(-it.first.y,it.first.x);if(mp.count(tmp))ans[i]+=mp[tmp]*it.second;}ans[i]/=2;}for(int i=1;i<=n;i++){//n個點分別為直角 mp.clear();for(int j=1;j<=n;j++){if(i==j)continue;mp[point[j]-point[i]]++;}for(int j=0;j<q;j++){Point tmp=vec[j]-point[i];tmp=Point(-tmp.y,tmp.x);if(mp.count(tmp))ans[j]+=mp[tmp];}}for(int i=0;i<q;i++)printf("%d\n",ans[i]); // cout<<ans[i]<<endl; //Time_test(); }總結
以上是生活随笔為你收集整理的CCPC秦皇岛gym102361A. Angle Beats的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Codeforces Round #72
- 下一篇: 农历七月十五是什么节 有什么讲究