2013年7月16日 星期二

d478: 共同的數 - 簡易版 (TLE)

http://zerojudge.tw/ShowProblem?problemid=d478
暴力解法 TLE
還是得排序在比較
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
 int m = 0,n = 0;
 const int k = 1000000;
 int s1[k],s2[k];
 
 while(cin>>m>>n)
  while(m--)
  {
   for(int i=0;i<n;i++)
   {
    s1[i]='\0';
    s2[i]='\0';
   }
   
   for(int a=0;a<n;a++)
    cin>>s1[a];
   for(int b=0;b<n;b++)
    cin>>s2[b];
   
   int count = 0;
   
   for(int c=0;c<n;c++)
    for(int d=0;d<n;d++)
     if(s1[c]==s2[d])
      count++;
   
   cout<<count<<endl;
  }
 
 return 0;
}

沒有留言:

張貼留言