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

hash....超了内存,怎么减少内存呀。。

Posted by tale8023 at 2016-07-22 00:17:50 on Problem 2002
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <numeric>
using namespace std;
bool t[40005][40005];
int r[1003],c[1003];
int main(){
    int n;
    while (cin>>n){
        memset(t,0,sizeof(t));
        memset(r,0,sizeof(r));
        memset(c,0,sizeof(c));
        if (0==n) break;
        for (int i=0;i<n;i++){
            cin>>r[i]>>c[i];
            t[r[i]+20000][c[i]+20000]=1;
        }
        int num=0;
        for (int i=0;i<n;i++){
            for (int j=0;j<n;j++){
                if (i==j) continue;
                int x1=r[i]+(c[i]-c[j]);
                int y1=c[i]-(r[i]-r[j]);
                int x2=r[j]+(c[i]-c[j]);
                int y2=c[j]-(r[i]-r[j]);
                int x3=r[i]-(c[i]-c[j]);
                int y3=c[i]+(r[i]-r[j]);
                int x4=r[j]-(c[i]-c[j]);
                int y4=c[j]+(r[i]-r[j]);
                if ((1==t[x1+20000][y1+20000])&&(1==t[x2+20000][y2+20000]))
                    num++;
                if ((1==t[x3+20000][y3+20000])&&(1==t[x4+20000][y4+20000]))
                    num++;
            }
        }
        cout<<num/8<<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