#14801: c 測資#3吃TLE 求大大解答


antonychen5ds2@gmail.com (HOSHI)

學校 : 政治大學
編號 : 79724
來源 : [114.36.177.55]
最後登入時間 :
2024-03-28 17:04:02
b265. Q11286 - Conformity | From: [118.150.145.112] | 發表日期 : 2018-08-06 18:26

如題

跪求各位大大幫解

我寫的方法是有些粗糙

請大家幫我看看如何優化

謝謝

#include<stdio.h>

int main(){
int student = 0;
while(scanf("%d", &student) != EOF){
int alass[10000][5] = {};
if(student == 0){
break;
}
for(int i = 0;i < student;++i){
for(int j = 0;j < 5;++j){
scanf("%d", &alass[i][j]);
}
}
for(int i = 0;i < student;++i){
for(int j = 0;j < 4;++j){
for(int k = 0;k < 4-j;++k){
if(alass[i][k] > alass[i][k+1]){
int tmp = alass[i][k];
alass[i][k] = alass[i][k+1];
alass[i][k+1] = tmp;
}
}
}
}
char num[10000][16] = {};
for(int i = 0;i < student;++i){
for(int j = 0;j < 5;++j){
int count = 2;
for(int k = 0;k < 3;++k){
num[i][count+j*3] = alass[i][j] % 10 + '0';
alass[i][j] /= 10;
count--;
}
}
}
int check[10000] = {};
char result[10000][16] = {};
int sum[10000] = {};
int count2 = 0;
for(int i = 0;i < student;++i){
if(check[i] == 0){
for(int j = 0;j < 15;++j){
result[count2][j] = num[i][j];
}
check[i] = 1;
sum[count2] = 0;
for(int j = 0;j < student;++j){
int a = 0;
for(int k = 0;k < 15;++k){
if(result[count2][k] != num[j][k]){
a = 1;
break;
}
}
if(a == 0){
sum[count2] += 1;
check[j] = 1;
}
}
count2++;
}
}
int max = 0;
for(int i = 0;i < student;++i){
if(sum[i] > max){
max = sum[i];
}
}
int output = 0;
for(int i = 0;i < student;++i){
if(sum[i] == max){
output += max;
}
}
printf("%d\n", output);
}
return 0;
}

 
#14802: Re:c 測資#3吃TLE 求大大解答


antonychen5ds2@gmail.com (HOSHI)

學校 : 政治大學
編號 : 79724
來源 : [114.36.177.55]
最後登入時間 :
2024-03-28 17:04:02
b265. Q11286 - Conformity | From: [118.150.145.112] | 發表日期 : 2018-08-06 18:29

如題

跪求各位大大幫解

我寫的方法是有些粗糙

請大家幫我看看如何優化

謝謝

#include

int main(){
int student = 0;
while(scanf("%d", &student) != EOF){
int alass[10000][5] = {};
if(student == 0){
break;
}
for(int i = 0;i < student;++i){
for(int j = 0;j < 5;++j){
scanf("%d", &alass[i][j]);
}
}
for(int i = 0;i < student;++i){
for(int j = 0;j < 4;++j){
for(int k = 0;k < 4-j;++k){
if(alass[i][k] > alass[i][k+1]){
int tmp = alass[i][k];
alass[i][k] = alass[i][k+1];
alass[i][k+1] = tmp;
}
}
}
}
char num[10000][16] = {};
for(int i = 0;i < student;++i){
for(int j = 0;j < 5;++j){
int count = 2;
for(int k = 0;k < 3;++k){
num[i][count+j*3] = alass[i][j] % 10 + '0';
alass[i][j] /= 10;
count--;
}
}
}
int check[10000] = {};
char result[10000][16] = {};
int sum[10000] = {};
int count2 = 0;
for(int i = 0;i < student;++i){
if(check[i] == 0){
for(int j = 0;j < 15;++j){
result[count2][j] = num[i][j];
}
check[i] = 1;
sum[count2] = 0;
for(int j = 0;j < student;++j){
int a = 0;
for(int k = 0;k < 15;++k){
if(result[count2][k] != num[j][k]){
a = 1;
break;
}
}
if(a == 0){
sum[count2] += 1;
check[j] = 1;
}
}
count2++;
}
}
int max = 0;
for(int i = 0;i < student;++i){
if(sum[i] > max){
max = sum[i];
}
}
int output = 0;
for(int i = 0;i < student;++i){
if(sum[i] == max){
output += max;
}
}
printf("%d\n", output);
}
return 0;
}

抱歉手殘 應該是測資#2


 
ZeroJudge Forum