Codeforces GYM 101147F. Bishops Alliance
传送门:http://codeforces.com/gym/101147/problem/F
题目翻译
一些棋子分别在(\left ( X_{i},Y_{i} \right )),有属性(P_{i}),如果一条对角线上的棋子之间两两满足(\left | X_i – Y_i \right | \geqslant P_i^2+P_j^2+C-1),即可形成一条防守线。求最长防守线长度。
题解
按照对角线,把所有点分类。
新的(i),如果对于一个已经符合的团体,最右边的点(j),有(X_i > X_j),(X_i – P_i^2\geqslant X_j + P_j^2 + C -1),那么点(i)能加入这个点(j),所在的集合。
令(A_i =X_i – P_i^2 ),(B_i=X_i + P_i^2 + C -1)且(A_i<B_i)。
所以对于同一条对角线上面的点,按照(X)排序,单调队列维护(B_i)即可。
代码
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 |
#include<cstdio> #include<algorithm> #include<vector> #define LL long long using namespace std; const int Maxn=1e5; vector<int> diag[2][Maxn*2+5]; struct Bishops{ int x,y; LL p; LL P1,P2; }; Bishops bs[Maxn+5]; LL C; int n,m; int Ans=1; inline bool cmpBishop(int a,int b){ return bs[a].x<bs[b].x; } int stk[Maxn+5]; int top; inline int solveDiagonal(vector<int> &vec){ sort(vec.begin(),vec.end(),cmpBishop); int siz=vec.size(); if (siz==0) return 0; stk[top=1]=vec[0]; //printf("%d ",vec[0]); for (int i=1;i<siz;i++){ int j=top; if (j>0 && bs[vec[i]].P1<bs[stk[j]].P2) j--; if (j==top || bs[stk[j+1]].P2>bs[vec[i]].P2) stk[++j]=vec[i]; top=max(top,j); //printf("%d ",vec[i]); } //printf("\n"); return top; } inline void solve(){ for (int i=0;i<=Maxn*2;i++){ diag[0][i].clear(); diag[1][i].clear(); } scanf("%d%d%I64d",&n,&m,&C); for (int i=1;i<=m;i++){ scanf("%d%d%I64d",&bs[i].x,&bs[i].y,&bs[i].p); diag[0][bs[i].x+bs[i].y].push_back(i); diag[1][bs[i].x-bs[i].y+Maxn].push_back(i); bs[i].p*=bs[i].p; bs[i].P1=(LL)bs[i].x-bs[i].p; bs[i].P2=(LL)bs[i].x+bs[i].p+C-1LL; } if (m==0){ printf("0\n"); return; } int Ans=1; for (int i=0;i<=1;i++) for (int j=0;j<=Maxn*2;j++) Ans=max(Ans,solveDiagonal(diag[i][j])); printf("%d\n",Ans); } int main(){ freopen("bishops.in","r",stdin); int T=0; while(scanf("%d",&T)!=EOF){ for (int i=1;i<=T;i++) solve(); } return 0; } |

原文链接:Codeforces GYM 101147F. Bishops Alliance
WNJXYKの博客 版权所有,转载请注明出处。
还没有任何评论,你来说两句吧!