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
北京大学《ACM-ICPC竞赛训练》暑期课面向全球招生。容量有限,报名从速!

Re:我的代码无敌了

Posted by x604078488 at 2013-09-14 01:51:19 on Problem 1001
In Reply To:也给一些测试数据(总结了前辈的) Posted by:ljxluois at 2007-08-14 01:34:10
这上面的全测试过了还是WA....我把VC6.0编译的发上来...谁给看看...
// Note:Your choice is C++ IDE
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
vector<int> pow(char *R,int n){
	int r[5];
    vector<int> s(100,0);
    vector<int> y(100,0);
    y[99]=1;
    for(int i=0,j=0;R[i];i++){
    	if(R[i]!='.'){
    		r[j]=R[i]-48;
    		j++;}
    }
    for(i=0;i<n;i++){
    	for(int q=0;q<100;q++)
    	s[q]=0;
        for(int p=99;p>=4;p--){
    		for(int k=4;k>=0;k--){
    			s[p+k-4]+=y[p]*r[k];}
        }
    	for(int l=99,m=0;l>0;l--){
    		m=s[l];
    		s[l]=s[l]%10;
    		s[l-1]+=m/10;}
    	for(q=0;q<100;q++)
    	y[q]=s[q];
    }
    return  s;
}
	
int main()
{
    char r[10];
    int n,pot=0;
    while(scanf("%s %d",r,&n)!=EOF){
    for(int i=0;r[i];i++)
    if(r[i]=='.')
    pot=5-i;
    if(pot==0){
    	for(i=0;i<5;i++){
    		r[i]=r[i+1];}
    }
    vector<int> answer(pow(r,n));
    int j,zero=1;
    for(i=0;i<100;i++){
    	if(answer[i]!=0){
    		zero=0;
    		break;}
    }
    if(zero==1){
    	cout<<zero-1;
    	return 0;}
    for(i=0;i<100&&answer[i]==0;i++){
    if(i+pot*n==99){
    	cout<<".";
    	j=i+1;
    	break;}
    j=i+1;}
    for(;j<100;j++){
    	int pp=0,q=j+1;
    	if(j==99)
    	pp=1;
    	for(;q<100;q++){
    		if(answer[q]!=0){
    			pp=1;
    			break;}
    	}
    	cout<<answer[j];
    	if(j>98-pot*n&&pp==0)
    	break;
    	if(j+pot*n==99&&pp==1&&j!=99)
    	cout<<".";}
    cout<<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