ZOJ 2975 Kinds of Fuwas(暴力)
2016-02-19 17:44
218 查看
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2975
给出n*m的矩阵,要求算出四个角类型相同的小矩形的数目
使用暴力枚举任意两列,然后枚举每一行,统计每行的两列相同的个数,然后使用组合数求解,时间复杂度250^3.
给出n*m的矩阵,要求算出四个角类型相同的小矩形的数目
使用暴力枚举任意两列,然后枚举每一行,统计每行的两列相同的个数,然后使用组合数求解,时间复杂度250^3.
#include<iostream> #include<cstdio> #include<set> #include<string> #include<string.h> #include<cstring> #include<vector> #include<map> #include<queue> #include<stack> #include<cctype> #include<algorithm> #include<sstream> #define mt(a) memset(a,0,sizeof a) #define fl(a,b,c) fill(a,b,c) #define inf 1000000000+7 using namespace std; typedef long long ll; char graph[300][300]; ll g[5]; int main() { int T; cin >> T; while (T--) { int n, m;; ll ans = 0; memset(graph, 0, sizeof graph); memset(g, 0, sizeof g); scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) scanf("%s", graph[i]); for (int i = 0; i < m; i++) { for (int j = i + 1; j < m; j++) { memset(g, 0, sizeof g); for (int k = 0; k < n; k++) { if (graph[k][i] == graph[k][j]) { if (graph[k][i] == 'B')g[0]++; else if (graph[k][i] == 'J')g[1]++; else if (graph[k][i] == 'H')g[2]++; else if (graph[k][i] == 'Y')g[3]++; else if (graph[k][i] == 'N')g[4]++; } } for (int k = 0; k < 5; k++) { if(g[k])ans += ((g[k] * (g[k] - 1)) / 2); } } } printf("%lld\n", ans); } return 0; }
相关文章推荐
- java web开发实现properties文件的读取与解析
- okhttp感想
- apple用什么方式实现对一个对象的KVO
- 正则中关于修饰符g以及exec和match区别的一个小demo
- 第5章 理解RemoteViews
- LeetCode - 29. Divide Two Integers
- ArrayList、LinkedList、 Vector、Map 用法比较
- 自动换行的标签。
- springmvc+quartz定时任务的实现
- Centos系统下Lamp环境的快速搭建
- Xcode菜单功能中文翻译
- 进程间通信方式
- lamp or lnmp or lnamp有什么区别?安装哪个好?
- Spring ContextLoaderListener And DispatcherServlet Concepts
- Linux设备驱动安装的基本过程
- golang走起(一)对象与指针
- 数据库代理
- Spring实现AOP的4种方式
- js获取设备信息
- Oralce创建用户