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

大牛指点啊~~MLEMLEMLEMLE

Posted by hdoi at 2010-03-14 01:46:47
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
using namespace std;
#define N 10
int *getelem(int);
int findvalue(long n){
long count=0;
int i,j;
int value;
while(count<n){
for(i=0;i<9;i++){
for(j=0;j<=i;j++){
	count++;if(count==n){value=j+1; break;}}
}
for(i=9;i<sqrt(static_cast<long double>(n*2));i++){
for(j=0;j<9;j++){
	count++;if(count==n){value=j+1; break;}}
int j_value=j;
while(j_value<=i){
int temp=j_value+1;
int temp_col=j;
int *ptemp=getelem(temp);
while(*ptemp>=0&&*ptemp<=9){
	*ptemp++;
	count++;
    if(count==n){value=*(ptemp-1); break;}
	j++;}
j_value++;
}
}
}
return value;
}

int *getelem(int n){
char *strnum;
strnum=new char[10];
_itoa(n,strnum,10);
int *elemarray;
elemarray=new int[strlen(strnum)];
int i=0;
while(i<strlen(strnum)){
elemarray[i]=strnum[i++]-48;
}
return elemarray;
}

int main(){
long test[N+1];
int t=0;
while(cin>>test[t++]&&t<=test[0]);
int i=1;
while(i<t){
cout<<findvalue(test[i++])<<endl;}
return 0;
}

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