码迷,mamicode.com
首页 > 其他好文 > 详细

uva 1152

时间:2017-05-02 22:07:04      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:names   amp   code   ios   using   scan   const   --   ring   

中途相遇法

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=4000+10;
int a[maxn][5];
int zz[maxn*maxn];
int n,t;
int main()
{   scanf("%d",&t);
   while(t--)
   {
       scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<4;j++)
            scanf("%d",&a[i][j]);
    }
    int cnt=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
        zz[cnt++]=a[i][0]+a[j][1];
        sort(zz,zz+cnt);
        int ans=0;
        for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
        {  int hh=-a[i][2]-a[j][3];
            ans+=upper_bound(zz,zz+cnt,hh)-lower_bound(zz,zz+cnt,hh);
        }
    printf("%d\n",ans);
    if(t) printf("\n");
   }
    return 0;
}

 

uva 1152

标签:names   amp   code   ios   using   scan   const   --   ring   

原文地址:http://www.cnblogs.com/Wangwanxiang/p/6798562.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!