CodeForces Gym101147F Bishops Alliance

Source: 2016-2017 ACM-ICPC, Egyptian Collegiate Programming Contest (ECPC 16)

Problem: nn 的棋盘上有 m 个棋子,每个棋子i有属性 pi ,如果两个棋子在同一条斜线上,并且满足 |xixj|+1p2i+p2j+C ,则称之为合法的。求最大集合并且两两合法。

Idea: 很明显,依次考虑棋盘上的每条对角线。不等式移项后, 1+xip2iCxj+p2j , 则每个物品i具有两个属性,即 (1+xip2iC) (xi+p2i) ,将其按照 (xi+p2i) 的大小排序后,发现物品的大小关系是具有传递性的,DP或者直接贪心就可以了。

Code:

#include<bits/stdc++.h>
using namespace std;

//#define LOCAL
#define fi first
#define se second
#define pb push_back
#define ALL(A) (A).begin(), (A).end()
#define CLR(A, X) memset(A, X, sizeof(A))
typedef long long LL;
typedef pair<LL, LL> PII;
const double eps = 1e-10;
const double PI = acos(-1.0);
const auto INF = 0x3f3f3f3f;
int dcmp(double x) { if(fabs(x) < eps) return 0; return x<0?-1:1; }

const int MAXN = 4e5+5;

vector<PII> G[MAXN];

int main() {
#ifndef LOCAL
    freopen("bishops.in", "r", stdin);
#endif // LOCAL
    int X;
    scanf("%d", &X);
    while(X--) {
        int n, m, C;
        scanf("%d%d%d", &n, &m, &C);
        while(m--) {
            int x, y; LL p;
            scanf("%d%d%lld", &x, &y, &p);
            p *= p;
            G[x+y-2].pb({x+p, 1+x-p-C});
            G[x-y-2+3*n].pb({x+p, 1+x-p-C});
        }
        int ans = 0;
        for(int k = 0; k < 4*n; k++) if(G[k].size()) {
            sort(ALL(G[k]));
            int j = 0, t = 0;
            for(int i = 0; i < G[k].size(); i++) {
                if(G[k][i].se >= G[k][j].fi) {
                    t++;
                    j = i;
                }
            }
            ans = max(ans, t);
        }
        printf("%d\n", ans+1);
        for(int i = 0; i <= 4*n; i++) G[i].clear();
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值