您的位置:首页 > 其它

1054. The Dominant Color (20)

2015-01-30 11:59 337 查看
点击打开链接

map思维广啊!对应关系这样存储!!

用hash直接内存超过限制

//方法1:用vector存放node{data,times},但是其实查找不好做,因为此时tmp.data=x,而times未知,是无法知道的
//方法2:用vector存放node的下标,但是还是要创建node数组,数组太大了,仍然开不出来
//方法3:用map存放data与times的对应值
#include <cstdio>
#define MAX 123123
#include <map>
using namespace std;
map<int,int>mp;
int main(){
freopen("in.txt","r",stdin);
int m,n;
scanf("%d %d",&m,&n);
int maxx=-1;
int maxd=-1;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
int x;
scanf("%d",&x);
getchar();
map<int,int>::iterator it=mp.find(x);
if(it!=mp.end()){
it->second++;
}else{
mp[x]=1;
}

if(maxx<mp[x]){
maxx=mp[x];
maxd=x;
}
}
}
printf("%d\n",maxd);
return 0;
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: