zoukankan      html  css  js  c++  java
  • 【例题 8-3 UVA

    【链接】 我是链接,点我呀:)
    【题意】

    在这里输入题意

    【题解】

    显然中间相遇。 自己写了个hash处理一下冲突就可以了。

    【代码】

    /*
      	1.Shoud it use long long ?
      	2.Have you ever test several sample(at least therr) yourself?
      	3.Can you promise that the solution is right? At least,the main ideal
      	4.use the puts("") or putchar() or printf and such things?
      	5.init the used array or any value?
      	6.use error MAX_VALUE?
      	7.use scanf instead of cin/cout?
      	8.whatch out the detail input require
    */
    /*
        一定在这里写完思路再敲代码!!!
    */
    #include <bits/stdc++.h>
    const int MOD = 2000007;
    using namespace std;
    
    const int N = 4e3;
    
    struct node{
        int x,num;
        node *nex;
        node(){
            x = 0;num = 0;nex=NULL;
        }
        node(int xx){
            x = xx;num = 1;nex=NULL;
        }
    };
    
    int n,a[4][N+10];
    node *Hash[MOD+10];
    
    void inc(int temp){
        int x = abs(temp)%MOD;
        node *p = Hash[x];
        while (p->nex!=NULL){
            p = p->nex;
            if(p->x==temp){
                p->num++;
                return;
            }
        }
        p->nex = new node(temp);
    }
    
    int getnum(int temp){
        int x= abs(temp)%MOD;
        node *p = Hash[x];
        while (p->nex!=NULL){
            p = p->nex;
            if(p->x==temp) return p->num;
        }
        return 0;
    }
    
    int main(){
    	#ifdef LOCAL_DEFINE
    	    freopen("rush_in.txt", "r", stdin);
    	#endif
    
    	int T,kase = 0;
    	scanf("%d",&T);
    	while (T--){
            for (int i = 0;i < MOD;i++) Hash[i] = new node();
            if (kase>0) puts("");
            kase++;
            scanf("%d",&n);
            for (int i = 1;i <= n;i++)
                for (int j = 0;j < 4;j++)
                    scanf("%d",&a[j][i]);
            for (int i = 1;i <= n;i++)
                for (int j = 1;j <= n;j++)
                    inc(-a[0][i]-a[1][j]);
    
            long long ans = 0;
            for (int i = 1;i <= n;i++)
                        for (int j = 1;j <= n;j++)
                            ans += getnum(a[2][i]+a[3][j]);
            printf("%lld
    ",ans);
    	}
    
    	return 0;
    }
    
  • 相关阅读:
    神经网络
    密度峰值聚类
    kylin从入门到实战:实际案例
    [时间序列分析][3]--自相关系数和偏自相关系数
    时间序列分析之指数平滑法(holt-winters及代码)
    时间序列模型
    python3.5如何安装statsmodels包?
    时间序列分析和预测
    Xshell6和Xftp6 破解免安装版,无窗口多开限制
    优化问题
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8178839.html
Copyright © 2011-2022 走看看