0
已解决
张皓然
中级光能
中级光能
今天的第6次模拟大家都考了吧。我要感谢苍天,让我进化了!
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m;
struct stu{
int id;
int x[505];
int a[105];
int sum;
int zws;
}a[1005];
bool cmp(int x,int y){
return x<y;
}
bool cmp2(stu x,stu y){
if(x.sum!=y.sum){
return x.sum>y.sum;
}
return x.zws>y.zws;
}
int main(){
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
cin>>n>>m;
for(int i=1;i<=n;i++){
a[i].id=i;
for(int j=1;j<=m;j++){
cin>>a[i].x[j];
a[i].a[a[i].x[j]]++;
a[i].sum=max(a[i].sum,a[i].a[a[i].x[j]]);//金色传说
}
int cnt=0,maxn=0;
for(int j=1;j<=m;j++){
if(a[i].a[a[i].x[j]]==a[i].sum){//
maxn=max(maxn,a[i].x[j]);
}
}
a[i].sum=maxn;
}
for(int i=1;i<=n;i++){
sort(a[i].x+1,a[i].x+1+m,cmp);//金色传说
if(m%2==1){
a[i].zws=a[i].x[m/2+1];
}else{
a[i].zws=(a[i].x[m/2]+a[i].x[m/2+1])/2;
}
}
sort(a+1,a+1+n,cmp2);
cout<<a[1].id<<" "<<a[1].sum<<" "<<a[1].zws;
fclose(stdin);
fclose(stdout);
return 0;
}
结构体数组排序!!
0
0
0
李泽屿
新手启示者
新手启示者
我不知道我的对不对
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int n,m;
struct r{
int t[505],zj,zwj,idx,b[105],maxz;
}a[1005];
bool cmp(r a,r b){
if(a.zj!=b.zj) return a.zj>b.zj;
return a.zwj>b.zwj;
}
int main(){
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
cin>>n>>m;
for(int i=1;i<=n;i++){
a[i].idx=i;
for(int j=1;j<=m;j++){
cin>>a[i].t[j];
a[i].b[a[i].t[j]]++;
a[i].maxz=max(a[i].maxz,a[i].b[a[i].t[j]]);
}
sort(a[i].t+1,a[i].t+m+1);
for(int j=1;j<=m;j++){
if(a[i].maxz==a[i].b[a[i].t[j]]){
a[i].zj=max(a[i].zj,a[i].t[j]);
}
}
if(m%2==1){
a[i].zwj=a[i].t[m/2+1];
}else{
a[i].zwj=(a[i].t[m/2+1]+a[i].t[m/2])/2;
}
}
sort(a+1,a+n+1,cmp);
cout<<a[1].idx<<" "<<a[1].zj<<" "<<a[1].zwj;
fclose(stdin);
fclose(stdout);
return 0;
}
0
王海成
初级天翼
初级天翼
#include<bits/stdc++.h>
using namespace std;
int n,m,a[1005][505],maxn[1005],zj[1005],t[1000005],mx,id,h;
int main(){
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
if(a[i][j]>maxn[i]){
maxn[i]=a[i][j];
}
t[j]=a[i][j];
}
sort(t+1,t+m+1);
/*for(int j=1;j<=m;j++){
cout<<t[j]<<' ';
}*/
if(m%2!=0){
zj[i]=t[int(m/2)+1];
}
else {
zj[i]=t[(m/2+(m/2+1))/2];
}
for(int j=1;j<=m;j++){
t[j]=0;
}
if(maxn[i]>mx){
if(h<zj[i]){
mx=maxn[i];
h=zj[i];
id=i;
}
}
}
cout<<id<<' '<<mx<<' '<<h;
fclose(stdin);
fclose(stdout);
return 0;
}
可我是这样做的
0
0
0
0
杨弘毅
中级光能
中级光能
#include<bits/stdc++.h>
using namespace std;
int a[505];
struct node{
int zs,zjs,bh;
}b[1005];
bool cmp(node x,node y){
if(x.zs!=y.zs) return x.zs>y.zs;
return x.zjs>y.zjs;
}
int main(){
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
int t[105]={0},maxa=0;
for(int j=1;j<=m;j++){
cin>>a[j];
t[a[j]]++;
maxa=max(maxa,t[a[j]]);
}
sort(a+1,a+m+1);
if(m%2==0) b[i].zjs=(a[m/2]+a[m/2+1])/2;
else b[i].zjs=a[m/2+1];
for(int j=m;j>=1;j--){
if(t[a[j]]==maxa){
b[i].zs=a[j];
break;
}
}
b[i].bh=i;
}
sort(b+1,b+n+1,cmp);
cout<<b[1].bh<<" "<<b[1].zs<<" "<<b[1].zjs;
fclose(stdin);
fclose(stdout);
return 0;
}