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;
    }
    
  • 相关阅读:
    java 集合类说明与区别
    JAVA集合LIST MAP SET详解
    ThinkPHP文件上传
    ThinkPHP表单操作(未加验证)
    常用的正则表达式大全
    ThinkPHP模板替换
    ThinkPHP包含文件
    example_UEditor富文本编辑器
    ThinkPHP快捷方法汇总(随时添加)
    页面编码统一(转载)
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8178839.html
Copyright © 2011-2022 走看看