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了几十次,把结构体命名由node,改成edge就过了。哎!好没意思。

Posted by SL_OVER_SKY at 2014-09-15 21:39:30 on Problem 2785
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <iostream>
using namespace std;
#define MAXN 4100
#define pri 3999971
int a[MAXN],b[MAXN],c[MAXN],d[MAXN];
struct edge
{
    int v,cnt,next;
}edge[pri+1];
int head[pri+1],k;
int hash(int num)
{
    return (num+pri)%pri;
}
void add_hash(int num)
{
    int cur=hash(num);
    for(int i=head[cur];i!=-1;i=edge[i].next)
        if(edge[i].v==num) {edge[i].cnt++;return;}
    edge[k].v=num;
    edge[k].cnt=1;
    edge[k].next=head[cur];
    head[cur]=k++;
}
int find_hash(int num)
{
    int cur=hash(num);
    for(int i=head[cur];i!=-1;i=edge[i].next)
        if(edge[i].v==num) return edge[i].cnt;
    return 0;
}
int main()
{
    int n;
    while(cin>>n)
    {
        k=0;
        int i,j;
        long long ans=0;
        memset(head,-1,sizeof(head));
        for(i=0;i<n;i++)
            cin>>a[i]>>b[i]>>c[i]>>d[i];
        for(i=0;i<n;i++)
            for(j=0;j<n;j++) add_hash(a[i]+b[j]);
        for(i=0;i<n;i++)
            for(j=0;j<n;j++) ans+=find_hash(-c[i]-d[j]);
        cout<<ans<<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