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

对拍了 k<=10&&n<=10000的所有数据没发现错误,然后把所有用int的地方换成long long 就A了,现在还不知道怎马回事呢!!附Accepted代码

Posted by JiaJunpeng at 2011-11-19 21:11:38 on Problem 3531 and last updated at 2011-11-19 22:01:42
Source Code

Problem: 3531  User: JiaJunpeng 
Memory: 168K  Time: 32MS 
Language: C++  Result: Accepted 

Source Code 
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<cstring>
using namespace std;
long long k,len,wei,w,we[101],di[101],cnt,cont;
char str[101];
long long n,ans,ex[101],temp,f[101],an;
long long com(long long len)
{
    long long i,j,s,p,q;
    long long res=0;
    wei=w=0;
    for(i=1;i<len;i++)
    {
        for(j=1;j<k;j++)
        {
           if(i%2)
           {
              if(k%2||i==1)
              {
                temp=j;
                if(wei%2)
                   res-=temp;
                 else
                   res+=temp;
              }
           }
           else
           {
               temp=(long long)j*ex[i-1];
               if(wei%2)
                  res-=temp;
               else
                  res+=temp;
           }
           wei+=((long long)i*ex[i-1])%2;
           wei%=2;
        } 
        if(i>1)
           w+=((long long)(i-1)*(long long)(k-1)*ex[i-2])%2;
        w%=2;
        for(j=1;j<i;j++)
        {
            temp=0;
            for(s=0;s<k;s++)
            {
                if(i%2)
                {
                  if(k%2||j==1)
                  {
                    if((w+s*i%2+i-j)%2)
                       temp-=s;
                    else 
                       temp+=s;
                  }
                }
                else
                {
                    if((w+i-j)%2)
                       temp-=(long long)s*ex[j-1];
                    else
                       temp+=(long long)s*ex[j-1];
                }
            }
            if(i%2==0||k%2==0)
               res+=temp*(long long)(k-1)*ex[i-j-1];
        }
    }
    for(i=1;i<len;i++)
    {
         f[i]=0;
         for(j=1;j<=i;j++)
         {
            temp=0;
            for(s=0;s<k;s++)
            {
              if(len%2)
              {
                  if(ex[j-1]%2)
                  {
                     if((i-j+s)%2==0)
                        temp+=s;
                     else
                        temp-=s;
                  }
              }
              else
              {
                 if((i-j)%2==0)
                   temp+=(long long)s*ex[j-1];  
                 else
                   temp-=(long long)s*ex[j-1];
              }
            }
            if(len%2==0||k%2==0)
               f[i]+=temp*ex[i-j];
            else if(ex[i-j]%2)
               f[i]+=temp;
         }
    }
    return res;
}
int main()
{
    long long i,j,s,p,q,nn;
     while(scanf("%d%s",&k,str)==2)
     {
      len=strlen(str);
        ex[0]=1; 
        for(i=1;i<=len;i++)
           ex[i]=(long long)k*ex[i-1];
        f[0]=0;
        ans=com(len);
        n=0;
        temp=0;
        for(i=0;i<len;i++)
        {
           long long jmin,jmax;
           if(i==0)
              jmin=1;
           else
              jmin=0;
           if(i==len-1)
              jmax=str[i]-'0';
           else 
              jmax=str[i]-'0'-1;
           for(j=jmin;j<=jmax;j++)
           {
               long long tem;
               if(i%2==0)
                  tem=temp+j;
               else 
                  tem=temp-j;
               long long orz=(n+ex[len-i-1]*(long long)j%2-ex[len-1]%2)*(long long)len%2;
               orz+=wei;
               orz%=2;
               if(len%2)
               {
                  if(ex[len-1-i]%2)
                  {
                     if(orz%2==0)
                       ans+=tem;
                     else
                       ans-=tem;
                  }
               }
               else
               {
                   tem*=ex[len-1-i];
                   if(orz%2==0)
                      ans+=tem;
                   else
                      ans-=tem;
               }
               orz+=(i+1)%2;
               if(orz%2)
                   ans-=f[len-i-1];
               else
                   ans+=f[len-i-1];
           }
           if(i%2==0)
              temp+=str[i]-'0';
           else
              temp-=str[i]-'0';
           n+=(long long)(str[i]-'0')*ex[len-i-1];
        }  
        printf("%I64d\n",ans);
    }
    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