1054.The Dominant Color (20)
来源:互联网 发布:eclipse如何关联阿里云 编辑:程序博客网 时间:2024/06/04 19:28
1054.The Dominant Color (20)
pat-al-1054
2017-01-26
- 写了好久的一题,一开始用c写的,全部用数组手动查找,一个测试点超时,一个测试点出错
- 后来看到一个不错的思路:PAT 解题报告 1054. The Dominant Color (20)自己照着写了一下发现还是有一个测试点超时
- 于是又找了一个新的方法:1054. The Dominant Color (20)-PAT甲级真题写了发现那个测试点依旧超时,突然想起来cin比scanf耗时大,果然替换之后就不超时了
- 坑:如果使用了cin、cout,有测试点超时且感觉不是程序有问题,那么换成scanf和printf试试
- 强迫症的难过:一开始写的那个方法,那个出错的测试点到底是为什么?……可能我永远都不会知道了……
- map的使用
/** * pat-al-1054 * 2017-01-26 * Cpp version * Author: fengLian_s */#include<map>using namespace std;int main(){ int m, n;//m是列数,n是行数 scanf("%d %d", &m, &n); int half = m*n/2; //cout << "half = " << half << endl; map<int, int> color; for(int i = 0;i < m*n;i++) { int tmp; scanf("%d", &tmp);//大坑:有一个测试点运行超时是因为用cin输入耗时 color[tmp]++; //cout << tmp << ": " << color[tmp] << endl; if(color[tmp] > half) { printf("%d\n", tmp); break; } } return 0;}
-FIN-
0 0
- 1054. The Dominant Color (20)
- 1054. The Dominant Color (20)
- 1054. The Dominant Color (20)
- 1054. The Dominant Color (20)
- 1054. The Dominant Color (20)
- 1054. The Dominant Color (20)
- 1054. The Dominant Color (20)
- 1054. The Dominant Color (20)
- 1054. The Dominant Color (20)
- 1054. The Dominant Color (20)
- 1054. The Dominant Color (20)
- 1054. The Dominant Color (20)
- 1054. The Dominant Color (20)
- 1054. The Dominant Color (20)
- 1054. The Dominant Color (20)
- 1054. The Dominant Color (20)
- 1054. The Dominant Color (20)
- 1054. The Dominant Color (20)
- Android studio 运行错误
- php 仿 linux cat 命令实现代码
- TortoiseSVN签出项目出错
- 虚拟机里面的Ubuntu跟主机之间ping不通
- bootstrap的modal-remote两种加载方式【强化】
- 1054.The Dominant Color (20)
- Ubuntu虚拟机ping不通win7宿主机怎么办
- MultiAutoCompleteTextView和AutoCompleteTextView两个自动完成功能控件的使用
- 题目1001:A+B for Matrices
- Git的配置以及使用技巧
- PHP匿名函数、闭包、function use
- 谷哥的小弟学前端(10)——JavaScript基础知识(1)
- mfc_读取人物血蓝坐标
- 贪心算法解决数列作为顶点度数构造无向图问题