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

可恶,多组数据就wa,现贴wa代码如下,写的丑,权当纪念

Posted by xuesu at 2014-04-01 11:05:07 on Problem 1850
#include <iostream>
using namespace std;
char ans[11];
int a[10];
int c[27][27];
long long f[10];
void generc(){
	for(int i=1;i<27;i++)c[i][0]=c[i][i]=1;
	for(int i=2;i<27;i++){
		for(int j=1;j<27;j++){
			c[i][j]=c[i-1][j]+c[i-1][j-1];
		}
	}
}
void generf(){
	f[0]=0;
	for(int i=1;i<10;i++){
		f[i]=f[i-1]+c[26][i];
	}
}

long long calc(){
	int len=0;
	for(len=0;len<10;len++){
		if(ans[len]==0)break;
		a[len]=ans[len]-'a';
	}

	int former=0;
	long long res=0;
	res+=f[len-1];
	for(int i=0;i<len;i++){
		for(int j=former;j<a[i];j++){
			res+=c[25-j][len-1-i];
		}
		former=a[i]+1;
	}
	return res+1;
}
bool check(){
	int fl=true;
	int len=0;
	char former='a'-1;
	for(len=0;len<10;len++){
		if(ans[len]==0)break;
		if(ans[len]<=former){
			fl=false;
			break;
		}
		former=ans[len];
	}
	if(len==0)return false;
	return fl;
}
int main(){
	generc();
	generf();
	while(cin>>ans){
	if(check())cout<<calc()<<endl;
	else cout<<0<<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