#17385: 有辦法簡化程式嗎 一直TLE


isu10703014a (七個下雨天)

School : 義守大學
ID : 88718
IP address : [42.75.102.176]
Last Login :
2019-06-16 17:36:38
a291. nAnB problem | From: [42.77.38.89] | Post Date : 2019-04-06 21:38

#include <bits/stdc++.h>
using namespace std;
int main()
{
int a[4],b,c[4],x,y,C[10],D[10];
while(cin>>a[0]>>a[1]>>a[2]>>a[3])
{
cin>>b;
for(int k=0;k<b;k++)
{
x=0;
y=0;
cin>>c[0]>>c[1]>>c[2]>>c[3];
for(int i=0;i<4;i++)
{
if(a[i]==c[i])
{
x++;
}
}
for(int i=0;i<10;i++)
{
C[i]=0;
D[i]=0;
}
for(int i=0;i<4;i++)
{
C[a[i]]++;
D[c[i]]++;
}
for(int i=0;i<10;i++)
{
if(C[i]==D[i])
{
y=y+C[i];
}
if(C[i]<D[i])
{
y=y+C[i];
}
if(C[i]>D[i])
{
y=y+D[i];
}
}
y=y-x;
cout<<x<<"A"<<y<<"B"<<endl;
}
}
}

 
#17404: Re:有辦法簡化程式嗎 一直TLE


314159265358979323846264338327... (少年π)

School : 臺北市私立延平高級中學
ID : 69058
IP address : [203.72.178.252]
Last Login :
2019-06-20 16:46:37
a291. nAnB problem | From: [223.137.108.36] | Post Date : 2019-04-07 18:48

#include <bits/stdc++.h>
using namespace std;
int main()
{
int a[4],b,c[4],x,y,C[10],D[10];
while(cin>>a[0]>>a[1]>>a[2]>>a[3])
{
cin>>b;
for(int k=0;k<b;k++)
{
x=0;
y=0;
cin>>c[0]>>c[1]>>c[2]>>c[3];
for(int i=0;i<4;i++)
{
if(a[i]==c[i])
{
x++;
}
}
for(int i=0;i<10;i++)
{
C[i]=0;
D[i]=0;
}
for(int i=0;i<4;i++)
{
C[a[i]]++;
D[c[i]]++;
}
for(int i=0;i<10;i++)
{
if(C[i]==D[i])
{
y=y+C[i];
}
if(C[i]<D[i])
{
y=y+C[i];
}
if(C[i]>D[i])
{
y=y+D[i];
}
}
y=y-x;
cout<<x<<"A"<<y<<"B"<<endl;
}
}
}


優化I/O即可AC


 
#17492: Re:有辦法簡化程式嗎 一直TLE


isu10703014a (七個下雨天)

School : 義守大學
ID : 88718
IP address : [42.75.102.176]
Last Login :
2019-06-16 17:36:38
a291. nAnB problem | From: [223.139.251.47] | Post Date : 2019-04-15 00:08

#include <bits / stdc ++。h>
using namespace std;
int main()
{
int a [4],b,c [4],x,y,C [10],D [10];
while(cin >> a [0] >> a [1] >> a [2] >> a [3])
{
cin >> b;
for(int k = 0; k <b; k ++)
{
x = 0;
Y = 0;
CIN >> C [0] >> C [1] >> C [2] >> C [3];
for(int i = 0; i <4; i ++)
{
if(a [i] == c [i])
{
x ++;
}
}
對於(INT I = 0; I <10;我++)
{
C [1] = 0;
d [I] = 0;
}
對(INT I = 0; I <4;我++)
{
C [A [1] ++;
d [C [1] ++;
}
for(int i = 0; i <10;
i ++) {
if(C [i] == D [i])
{
y = y + C [i];
}
if(C [i] <D [i])
{
y = y + C [i];
}
if(C [i]> D [i])
{
y = y + D [i];
}
}
Y = YX;
COUT << X <<“A”<<Ÿ<<“B”<< ENDL;
}
}
}


優化I / O即可AC




小弟愚笨 怎麼樣可以優化I/O

 
#17493: Re:有辦法簡化程式嗎 一直TLE


isu10703014a (七個下雨天)

School : 義守大學
ID : 88718
IP address : [42.75.102.176]
Last Login :
2019-06-16 17:36:38
a291. nAnB problem | From: [223.139.251.47] | Post Date : 2019-04-15 02:00

#include <bits / stdc ++。h>
using namespace std;
int main()
{
int a [4],b,c [4],x,y,C [10],D [10];
while(cin >> a [0] >> a [1] >> a [2] >> a [3])
{
cin >> b;
for(int k = 0; k <b; k ++)
{
x = 0;
Y = 0;
CIN >> C [0] >> C [1] >> C [2] >> C [3];
for(int i = 0; i <4; i ++)
{
if(a [i] == c [i])
{
x ++;
}
}
對於(INT I = 0; I <10;我++)
{
C [1] = 0;
d [I] = 0;
}
對(INT I = 0; I <4;我++)
{
C [A [1] ++;
d [C [1] ++;
}
for(int i = 0; i <10;
i ++) {
if(C [i] == D [i])
{
y = y + C [i];
}
if(C [i] <D [i])
{
y = y + C [i];
}
if(C [i]> D [i])
{
y = y + D [i];
}
}
Y = YX;
COUT << X <<“A”<<Ÿ<<“B”<< ENDL;
}
}
}


優化I / O即可AC





已經AC 看了其他討論C++的TLE的處理方法 改成scanf printf 就AC了

謝謝堀北玲音學姊(X

 
ZeroJudge Forum