Created
January 1, 2017 22:44
-
-
Save jianminchen/1e1f0e98e1ebd1275b8ada5468dbd84e to your computer and use it in GitHub Desktop.
Hacker Earth - simple function - study code - full score, no timeout issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int hash1[3][1000][10]; | |
char str[1000]; | |
void hash(int l,int i,int t) | |
{ | |
int j; | |
for(j=0;j<l;j++) hash1[t][i][str[j]-48]=1; | |
} | |
int simple(int i,int j) | |
{ | |
int k; | |
for(k=9;k>0;k--) if(hash1[1][i][k]&&hash1[2][j][k]) break; | |
if(k%2==0) return 1; | |
else return 0; | |
} | |
int main() | |
{ | |
int t,n1,n2,l,i,j; | |
unsigned long long tot=0; | |
scanf("%d",&t); | |
while(t--) | |
{ | |
scanf("%d%d",&n1,&n2); | |
for(i=0;i<1000;i++) | |
{ | |
for(j=0;j<=9;j++) | |
{ | |
hash1[1][i][j]=0; | |
hash1[2][i][j]=0; | |
} | |
} | |
for(i=0;i<n1;i++) | |
{ | |
scanf("%s",str); | |
l=strlen(str); | |
hash(l,i,1); | |
} | |
for(i=0;i<n2;i++) | |
{ | |
scanf("%s",str); | |
l=strlen(str); | |
hash(l,i,2); | |
} | |
for(i=0;i<n1;i++) for(j=0;j<n2;j++) tot+=simple(i,j); | |
printf("%.3f\n",(float)((float)(tot)/(float)(n1*n2))); | |
tot=0; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment