Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

哪些大神们是怎么在0ms中完成的? 而且占用内存那么少? 有代码可看么?

Posted by taiji1985 at 2015-09-29 22:09:40 on Problem 1008
我的代码

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
char* hname[] = {"pop","no","zip","zotz","tzec","xul","yoxkin","mol","chen","yax","zac","ceh","mac","kankin","muan","pax","koyab","cumhu","uayet"};
char* tname[] = {"imix","ik","akbal","kan","chicchan","cimi","manik","lamat","muluk","ok","chuen","eb","ben","ix","mem","cib","caban","eznab","canac","ahau"};
int h_hash[]={7864320,6815744,204800,13107200,-1073741824,771751936,12582912,6291456,8192,768,800,1024,384,320,402653184,480,5242880,67108864,640};
unsigned int getHash(char* buf){
	char* p = buf;
	unsigned int h= (*p-'a') << 5 + (*(p+1)-'a');
	return h;
}
void pre(){
	for(int i=0;i<19;i++){
		printf("%d,",getHash(hname[i]));		
	}
}
int getHM(char* buf){
	int h = getHash(buf);
	for(int i=0;i<19;i++){
		if(h == h_hash[i]) return i;
	}
	return -1;
}
int main(int argc,char** argv) {
	//pre();
	int n ;
	int hy,hd,hm;
	char buf[4];
	char* tp =NULL;
	scanf("%d",&n);
	printf("%d\n",n);
	int td,tm,ty;
	while(n -- >0){
		
		scanf("%d. %s %d",&hd,&buf,&hy);
		hm = getHM(buf);
		
		long day = hy*365+ 20*hm + hd;
		//printf("hm = %d, day =%d",hm,day);
		
		
		td = day % 13 +1;
		tm = day % 20 ;
		tp = tname[tm];
		ty = day / 260;
		
		printf("%d %s %d\r\n",td,tp,ty);
	}
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator