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

救命啊!为什么超时??? 很好懂的程序~~~~~

Posted by qingl at 2005-12-18 00:41:49 on Problem 1019
#include <stdio.h>


void main(){
	int num,i;
	scanf("%d",&num);
	for(i=1;i<=num;i++){
		int m,j,p,de,w;
		de=1;		
		scanf("%d",&p);
		w=p;
		for(j=1;j<999999;j++){
			for(m=1;m<=j;m++){
				if(m<10){
					w=w-1;}
				if(9<m&&m<100){
					w=w-2;}
				if(99<m&&m<1000){
					w=w-3;}
				if(999<m&&m<10000){
					w=w-4;}
				if(9999<m&&m<100000)
					w=w-5;
				if(100000<=m&&m<=999999)
					w=w-6;
				if(w<=0){
					de=0;
					break;
				}
			}
				if(de==0)
					break;			
		}
		if(100000<=m&&m<=999999){
			switch(w){
		case 0:
			p=m%10;
			break;
		case -1:
			p=m%100-m%10;
			break;
		case -2:
			p=m%1000-m%100-m%10;
			break;
		case -3:
			p=m%10000-m%1000-m%100-m%10;
			break;
		case -4:
			p=m%100000-m%10000-m%1000-m%100-m%10;
			break;
		case -5:
			p=m-m%100000-m%10000-m%1000-m%100-m%10;
			break;
			}
		}
		if(10000<=m&&m<=99999){
			switch(w){
			case 0:
			p=m%10;
			break;
		case -1:
			p=m%100-m%10;
			break;
		case -2:
			p=m%1000-m%100-m%10;
			break;
		case -3:
			p=m%10000-m%1000-m%100-m%10;
			break;
		case -4:
			p=m-m%10000-m%1000-m%100-m%10;
			break;
			}
		}

		if(1000<=m&&m<=9999){
		switch(w){
		case 0:
			p=m%10;
			break;
		case -1:
			p=m%100-m%10;
			break;
		case -2:
			p=m%1000-m%100-m%10;
			break;
		case -3:
			p=m%10000-m%1000-m%100-m%10;
			break;
		}
		}
		if(100<=m&&m<=999){
			switch(w){
			case 0:
				p=m%10;
				break;
			case -1:
				p=m%100-m%10;
				break;
			case -2:
				p=m-m%100-m%10;
			}
		}
		if(10<=m&&m<=99){
			switch(w){
			case 0:
				p=m%10;
				break;
			case -1:
				p=m-m%10;
				break;
			}
		}
		if(m<10)
			p=m;
		printf("%d\n",p);
	}
}

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