poj 3251 Big Square
来源:互联网 发布:遗传算法区域描述器 编辑:程序博客网 时间:2024/06/07 11:29
也许你会诧异这题 有啥好写题解的。。?暴力枚举不就完了
但是
WA是自己作。没有看到不能平行。。T是真的。。。
O(n^4)怎么破?
靠瞎减减呗。
这里主要是感叹#define 的 快速。。最后实现的AC就是靠他。
define的优缺点
优点
提高了程序的可读性,同时也方便进行修改;
提高程序的运行效率:使用带参的宏定义既可完成函数调用的功能,又能避免函数的出栈与入栈操作,减少系统开销,提高运行效率;
3.宏是由预处理器处理的,通过字符串操作可以完成很多编译器无法实现的功能。比如##连接符。
缺点
由于是直接嵌入的,所以代码可能相对多一点;
嵌套定义过多可能会影响程序的可读性,而且很容易出错;
对带参的宏而言,由于是直接替换,并不会检查参数是否合法,存在安全隐患。
大概最后一点比较严重吧。
#include<cstdio> #include<algorithm> #include<cstring>#define ok(a,b,c,d) (a>=0&&b>=0&&c>=0&&d>=0&&a<=n&&b<=n&&c<=n&&d<=n)using namespace std;//by mars_chchar map[201][201],enter; int n,p,q,ans; int main() { scanf("%d",&n); for (register int i=1;i<=n;i++) { scanf("%c",&enter); for (register int j=1;j<=n;j++) scanf("%c",&map[i][j]); } for (register int x=1;x<=n;x++) for (register int y=1;y<=n;y++) if (map[x][y]=='J') for (register int i=n;i>=1;i--) for(register int j=n;j>=1;j--) { p=i-x;q=j-y; if(p*p+q*q<=ans) continue; if(map[i][j] == 'B' || (map[i][j] == map[x][y] && map[x][y] == '*')) continue; if (ok(x-q,i-q,y+p,j+p)&&(map[x-q][y+p]=='J')&&(map[i-q][j+p]=='J') || ok(y-p,j-p,i+q,x+q)&&(map[x+q][y-p]=='J')&&(map[i+q][j-p]=='J')) ans=p*p+q*q; } printf("%d",ans); return 0; }
1 0
- poj 3251 Big Square
- 【枚举】Big Square
- POJ3251:Big Square 题解
- 1661: [Usaco2006 Nov]Big Square 巨大正方形
- POJ3251-Big Square (C语言实现)
- poj 2362 Square
- poj 2362 Square
- poj 2362Square(DFS)
- poj 2362 Square
- POJ 2362 Square dfs
- poj 2362 Square
- Square DFS poj&hoj
- POJ-2362-Square
- POJ 2362 Square
- poj 2362 Square
- poj 2362 Square
- POJ 2362 Square
- POJ 2362 Square DFS
- libzdb --- mysql 的一个数据库连接池代码分析
- chipping rate码片速率
- 成绩排序
- JQuery判断数组中是否包含某个元素
- 脚本shell的使用
- poj 3251 Big Square
- Leetcode刷题记——11. Container With Most Water(装最多水的容器)
- C++25、lambda表达式
- CDH权限测试示例
- java 参数过滤,防止异常注入
- ntp错误:no server suitable for synchronization found
- SpringMVC+Maven+Hibernate+Modbus
- Android 沉浸式状态栏
- OpenStack命令集合