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;
}
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;
}
相关文章推荐
- 1054. The Dominant Color (20)
- 1054. The Dominant Color (20)
- PAT 1054. The Dominant Color (20)
- ZJU-PAT 1054. The Dominant Color (20) 浙大2013年上机复试第一题
- PAT 1054. The Dominant Color (20)(简单排序题(`vector<int>`利用`map<int,int>`来排序))
- PAT (Advanced) 1054. The Dominant Color (20)
- 1054. The Dominant Color (20)
- 1054. The Dominant Color (20)
- 【PAT甲级】1054. The Dominant Color (20)
- PAT (Advanced Level) Practise 1054 The Dominant Color (20)
- 1054. The Dominant Color (20)
- PAT_A 1054. The Dominant Color (20)
- PAT - 甲级 - 1054. The Dominant Color (20)(STL-map)
- PAT甲题题解-1054. The Dominant Color (20)-排序/map
- 1054. The Dominant Color (20)
- 1054. The Dominant Color (20)
- 1054. The Dominant Color (20)
- PAT (Advanced) 1054. The Dominant Color (20)
- 1054. The Dominant Color (20)
- PAT A 1054. The Dominant Color (20)