zoukankan      html  css  js  c++  java
  • [洛谷P1369]矩形

    题目大意:有$n(nleqslant300)$个点,每个点坐标范围在$[1sim100]$,求一个矩阵,使得边界上的点最多。

    题解:做一遍二维前缀和,直接暴力枚举两个顶点

    卡点:

    C++ Code:

    #include <algorithm>
    #include <cstdio>
    #define maxn 105
    int n, ans;
    int s[maxn][maxn];
    inline int calc(int lx, int ly, int rx, int ry) {
    	if (lx > rx || ly > ry) return 0;
    	return s[rx][ry] - s[rx][ly - 1] - s[lx - 1][ry] + s[lx - 1][ly - 1];
    }
    int main() {
    	scanf("%d", &n);
    	for (int i = 0, x, y; i < n; ++i) {
    		scanf("%d%d", &x, &y);
    		s[x][y] = 1;
    	}
    	for (int i = 1; i <= 100; ++i) {
    		for (int j = 2; j <= 100; j++) s[i][j] += s[i][j - 1];
    	}
    	for (int i = 2; i <= 100; ++i) {
    		for (int j = 1; j <= 100; j++) s[i][j] += s[i - 1][j];
    	}
    	for (int lx = 1; lx <= 100; ++lx)
    		for (int ly = 1; ly <= 100; ++ly)
    			for (int rx = lx; rx <= 100; ++rx)
    				for (int ry = ly; ry <= 100; ++ry) {
    					ans = std::max(ans, calc(lx, ly, rx, ry) - calc(lx + 1, ly + 1, rx - 1, ry - 1));
    				}
    	printf("%d
    ", ans);
    	return 0;
    }
    

      

  • 相关阅读:
    tap事件的原理详解
    获取地理位置
    获取高度
    JSON字符串与JSON对象的区别
    zepto方法
    javascript 中 click 和onclick有什么区别呢
    oninput,onpropertychange,onchange的用法和区别
    js实时监听input中值得变化
    sql lock
    数据库SQL优化大总结
  • 原文地址:https://www.cnblogs.com/Memory-of-winter/p/10336007.html
Copyright © 2011-2022 走看看