bzoj 1661: [Usaco2006 Nov]Big Square 巨大正方形 (枚举)
来源:互联网 发布:淘宝退款金额不能修改 编辑:程序博客网 时间:2024/05/19 13:06
题目描述
传送门
题解
枚举矩形的两个端点(同一条边上的),然后求出剩下的两个端点,判断是否合法,并更新答案。
代码
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#define N 103using namespace std;int cnt,n;int mp[N][N];struct data{ int x,y;}a[N*N];int cmp(data a,data b){ return a.x<b.x||a.x==b.x&&a.y<b.y;}int pow(int x){ return x*x;}int main(){ scanf("%d",&n); for (int i=1;i<=n;i++){ char s[N]; scanf("%s",s+1); for (int j=1;j<=n;j++) { if (s[j]=='B') mp[i][j]=-1; if (s[j]=='J') a[++cnt].x=i,a[cnt].y=j,mp[i][j]=1; } } int ans=0; for (int x1=1;x1<=n;x1++) for (int y1=1;y1<=n;y1++) for (int x2=x1+1;x2<=n;x2++) for (int y2=1;y2<=y1;y2++) { if (mp[x1][y1]==-1||mp[x2][y2]==-1) continue; int cnt=0; int len1=abs(x1-x2); int len2=abs(y1-y2); int x3=x1+len2; int y3=y1+len1; int x4=x2+len2; int y4=y2+len1; if (x3<1||y3<1||x3>n||y3>n) continue; if (x4<1||y4<1||x4>n||y4>n) continue; if (mp[x4][y4]==-1||mp[x3][y3]==-1) continue; cnt=mp[x1][y1]+mp[x2][y2]+mp[x3][y3]+mp[x4][y4]; if (cnt<3) continue; ans=max(ans,pow(len1)+pow(len2)); } printf("%d\n",ans);}
0 0
- bzoj 1661: [Usaco2006 Nov]Big Square 巨大正方形 (枚举)
- bzoj 1661: [Usaco2006 Nov]Big Square 巨大正方形(枚举)
- bzoj 1661 [Usaco2006 Nov]Big Square 巨大正方形
- |BZOJ 1661|暴力|[Usaco2006 Nov]Big Square 巨大正方形
- bzoj 1661: [Usaco2006 Nov]Big Square 巨大正方形 解题报告
- 1661: [Usaco2006 Nov]Big Square 巨大正方形
- bzoj 1662: [Usaco2006 Nov]Round Numbers 圆环数(枚举)
- 【枚举】Big Square
- BZOJ 1726: [Usaco2006 Nov]Roadblocks第二短路
- bzoj 1726: [Usaco2006 Nov]Roadblocks第二短路
- BZOJ 1726 [Usaco2006 Nov]Roadblocks第二短路
- [USACO5.3]巨大的牛棚Big Barn && 洛谷【p1387】最大正方形(动态规划)
- bzoj 1725: [Usaco2006 Nov]Corn Fields牧场的安排(状压DP)
- bzoj 1660: [Usaco2006 Nov]Bad Hair Day 乱发节(单调栈)
- bzoj 1660: [Usaco2006 Nov]Bad Hair Day 乱发节(单调栈)
- bzoj 1726: [Usaco2006 Nov]Roadblocks第二短路(A*第k短路)
- BZOJ 1660: [Usaco2006 Nov]Bad Hair Day 乱发节
- bzoj 1725: [Usaco2006 Nov]Corn Fields牧场的安排
- Oracle 12c 安装和卸载
- 细菌、真菌和病毒的区别
- Linux入门:信号(一)——基本概念
- C#学习笔记——关于定义属性
- AndroidStudio插件GsonFormat:根据Json自动生成JavaBean
- bzoj 1661: [Usaco2006 Nov]Big Square 巨大正方形 (枚举)
- angularJS CheckBox 绑定值
- Java 阻塞队列的6个常用方法与区别
- [转]python 代码自动生成的方法 (代码生成器)
- longest-consecutive-sequence
- 初学tensorflow一
- javascript 语句
- Ubuntu故障处理:Problem with Mergelist
- 转!!URL和URI区别