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

Re:用C++编译的,过不了(运行超时)----------用c重写,用c编译过了, 求大神解释下

Posted by anothing at 2014-10-25 08:42:05 on Problem 3844
In Reply To:用C++编译的,过不了 Posted by:anothing at 2014-10-25 08:41:00
#include <stdio.h>
#include <string.h>
 
int dn[1000003];
void main()
{
    int c,d,n;
	int num,i;
    int r,zero;
	int sum;

    scanf("%d",&c);
    while(c--)
    {
        memset(dn,0,sizeof(dn));
        sum = 0;
		zero=0;
        scanf("%d %d",&d,&n);
 
 
        for(i = 0; i < n; i++)
        {
            scanf("%d",&num);
			r=num%d;
			dn[zero]++;
			if(d-r+zero>=d)
			{
				sum+=dn[d-r+zero-d];
			}
			else
			{
				sum+=dn[d-r+zero];

			}
			if(zero<r)
			{
				zero=zero-r+d;
			}
			else
			{
				zero=zero-r;
			}
        }
        printf("%d\n",sum);
    }
}

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