| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
同样的算法,但是不同的头文件一个TLE 另一个AC(下有代码)Source
Problem Id:3067 User Id:tcxgsy
Memory:4036K Time:1015MS
Language:C++ Result:Time Limit Exceed
Source
#include<iostream>
#define max 1001
using namespace std;
int cross[max][max];
int run[max];
int main()
{
int N,M,K;
__int64 total,re;
int x,y,i;
int tests;
cin>>tests;
i=1;
while(tests--)
{
cin>>N>>M>>K;
memset(cross,0,sizeof(cross));
memset(run,0,sizeof(run));
while(K--)
{
cin>>x>>y;
cross[x][y]++;
}
total=0;
for(x=1;x<=N;x++)
{
re=0;
for(y=1;y<=M;y++)
{
total=total+re*run[y];
if(cross[x][y])
{
re+=cross[x][y];
run[y]=run[y]+cross[x][y];
}
}
}
printf("Test case %d: %I64d\n",i,total);
i++;
}
return 1;
}
Source
Problem Id:3067 User Id:tcxgsy
Memory:3980K Time:390MS
Language:C++ Result:Accepted
Source
#include<stdio.h>
#define max 1001
#include <string.h>
int cross[max][max];
int run[max];
int main()
{
int N,M,K;
__int64 total,re;
int x,y,i;
int tests;
scanf("%d",&tests);
i=1;
while(tests--)
{
scanf("%d%d%d",&N,&M,&K);
memset(cross,0,sizeof(cross));
memset(run,0,sizeof(run));
while(K--)
{
scanf("%d%d",&x,&y);
cross[x][y]++;
}
total=0;
for(x=1;x<=N;x++)
{
re=0;
for(y=1;y<=M;y++)
{
total=total+re*run[y];
if(cross[x][y])
{
re+=cross[x][y];
run[y]=run[y]+cross[x][y];
}
}
}
printf("Test case %d: %I64d\n",i,total);
i++;
}
return 1;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator