PAT (Advanced Level) 1054. The Dominant Color (20)

简单题

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;

int a[500000];
int n,m;

int main()
{
  scanf("%d%d",&n,&m);
  for(int i=0;i<n*m;i++) scanf("%d",&a[i]);
  sort(a,a+n*m); a[n*m]=774388357;

  int num=1;
  for(int i=1;i<=n*m;i++)
  {
    if(a[i]==a[i-1]) num++;
    else
    {
      if(num>n*m/2)
      {
        printf("%d\n",a[i-1]);
        break;
      }
      else num=1;
    }
  }
    return 0;
}
时间: 2024-12-19 07:08:09

PAT (Advanced Level) 1054. The Dominant Color (20)的相关文章

PAT Advanced 1054 The Dominant Color (20分)

Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional area is called the dominant color. A strictly dominant color takes mor

1054. The Dominant Color (20)

时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional ar

PAT:1054. The Dominant Color (20) AC(抓住最多的特点,处理不同和相同的情况,留下剩余的答案)

#include<stdio.h> int main() { int m,n,ans,tmp,times=0; scanf("%d%d",&m,&n); for(int i=0 ; i<n ; ++i) //[思维]题目找出现次数最多的一个,找到不同的,次数减少1,减少到0就换成输入的数字.找到相同的数字,次数+1.最后剩下的一定就是答案 { for(int j=0 ; j<m ; ++j) { scanf("%d",&

PAT:1054. The Dominant Color (20) AC(map法)

#include<stdio.h> #include<map> using namespace std; const int MAX=0x3fffffff; int main() { int m,n; map<int,int> count; //数字与出现次数的map映射 scanf("%d%d",&m,&n); for(int i=0 ; i<n ; ++i) { for(int j=0 ; j<m ; ++j) { i

PAT (Advanced Level) 1001. A+B Format (20)

简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> using namespace std; int a,b,tot,cnt; int u[20]; char ans[100]; int main() { while(~scanf("%d%d",&a,&b)) { a=a+b

PAT (Advanced Level) 1005. Spell It Right (20)

简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<vector> using namespace std; const int maxn=100+10; char s[maxn]; int tmp[maxn],tot; char ans[15][7]={ "zero&q

PAT (Advanced Level) 1019. General Palindromic Number (20)

简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<queue> #include<vector> using namespace std; int s[10000],tot; int n,b; bool check() { for(int i=0; i<=tot

PAT (Advanced Level) 1027. Colors in Mars (20)

简单题. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; void pri(int a) { if (a <= 9) printf("%d", a); else printf("%c", a-10+'A'); } void print(int a){ if (a >= 13

PAT (Advanced Level) 1011. World Cup Betting (20)

简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> using namespace std; double a[5][5],Max[5]; double ans=1; int main() { for(int i=1;i<=3;i++) for(int j=1;j<=3;j++) scanf(&qu