Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
暴搜老是TLE,加了个诡异的剪枝,居然过了875MSbool check(char * sa, char * sb) { int an[30], bn[30]; memset(an, 0, sizeof(an)); memset(bn, 0, sizeof(bn)); int i = 0, alen = strlen(sa), blen = strlen(sb); for(i = 0; i < alen; i ++) an[sa[i]-'a'] ++; for(i = 0; i < blen; i ++) bn[sb[i]-'a'] ++; int sum = 0; for(i = 0; i < 30; i ++) sum += abs(an[i] - bn[i]); return (sum <= 2); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator