【A + B + C + D】 问题

A + B + C + D

Time Limit: 40000/20000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 130    Accepted Submission(s): 44

Problem Description
Little Robert asked his mother for two cents. "What did you do with
the money I gave you yesterday?""I gave it to a poor old woman," he
answered."You're a good boy," said the mother proudly. "Here are
two cents more. But why are you so interested in the old
woman?""She is the one who sells the candy."A joke, here
entered
Below n four tuple (A, B, C, D), respectively, from the A, B, C, D
selected a, b ,c ,d To calculate the number of combinations of
a+b+c+d = 0;
 
Input
The first line of the input file contains the size of the lists n
(1<= n <= 4000)
Then every line containing four integer values (with absolute value
as large as 2^28 )
 
Output
For each input file, your program has to write the number whose sum
is zero
 
Sample Input
6 -45 22 42
-16 -41 -27 56
30 -36 53 -37
77 -36 30 -75
-46 26 -38
-10
62 -32 -54 -6 45
 
Sample Output
5
 
 
 
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

;

int n;
int s1[maxn*maxn];
int s2[maxn*maxn];
int a[maxn],b[maxn],c[maxn],d[maxn];

int main()
{
//   freopen("in.txt", "r", stdin);
    while(~scanf("%d", &n))
    {;i<n;i++)
        scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
    ;i<n;i++)
        ;j<n;j++)
            s1[i*n+j]=a[i]+b[j];
    ;i<n;i++)
        ;j<n;j++)
            s2[i*n+j] = c[i]+d[j];
    sort(s1,s1+n*n);
    sort(s2,s2+n*n);
    ;
    ;
    ;i<n*n;i++)
    {
         && s1[i]+s2[r]>)
            r--;
        )break;
        int tmp = r;
         && s1[i]+s2[tmp] == )
            ans++, tmp--;
    }
    printf("%d\n", ans);
    }
    ;
}

随机推荐

  1. 深入理解javascript的getTime方法

    1.理解getTime getTime() 方法返回一个时间的格林威治时间数值. 可以使用这个方法把一个日期时间赋值给另一个Date 对象. 语法: dateObj.getTime() 参数: 无. ...

  2. 千呼万唤始出来!—— GG(高仿QQ)终于有移动端了!(技术原理、实现、源码)

    首先要感谢大家一直以来对于GG的关注和支持!GG的不断完善与大家的支持分不开! 从2013年最初的GG1.0,到后来陆续增加了网盘功能.远程协助功能.离线文件功能.群聊功能.语音聊天功能.视频聊天功能 ...

  3. oracle中number类型的数据使用as string 得到的值为null

    1,如果数据的运行时类型(和数据库字段类型相同)不是字符串类型,比如number/date等,将ds.Tables[0].Rows[i][j] 调用 as string 时,不管 这个字段是否有值,这 ...

  4. 使用Hibernate框架技术时,对项目进行的配置

    1.在需要使用Hibernate框架技术的项目上单击鼠标右键,在弹出的菜单中选择MyEclipse-->Add Hibernate Capabilities,打开Add Hibernate Ca ...

  5. mybatis随意sql语句

    mybatis的mapper.xml随意sql语句, 不管表之间存不存在关系, 都可以使用, 但注意resultMap中一定要指定查询数据返回的列 或 对象(其实就是多列封装到一个对象中) <? ...

  6. centos 6&period;X 安装node

    1.源码安装 Source Code yum -y install gcc make gcc-c++ openssl-devel wget //yum下载相关的依赖包 wget http://node ...

  7. 转 java&period;lang&period;ClassNotFoundException&colon; org&period;apache&period;commons&period;lang&period;exception&period;NestableRuntimeException

    转自:http://blog.csdn.net/zb0567/article/details/7893063 java.lang.ClassNotFoundException: org.apache. ...

  8. 转账示例(三):service层面实现(线程管理Connection)(本例采用QueryRunner来执行sql语句,数据源为C3P0)

    缺点:Service层面还是不应该出现关于事务的操作1.自行创建C3P0Uti,account数据库,导入Jar包 2.Dao层面 接口: package com.learning.dao; impo ...

  9. 主java程序猿知识体系结构

    zuoxiaolong博客园<浅谈程序猿书箱的选择,你会如何选择自己的爱书呢>一文,链接如下:http://www.cnblogs.com/zuoxiaolong/p/life19.htm ...

  10. ubuntu下发布asp&period;net core并用nginx代理之旅

    asp.net core 1.0.1发布已有些日子了,怀着好奇的心情体验了把ubuntu下的asp.net core 系统运行环境:ubuntu 16.0.4 for developer 首先搭建.n ...

上一篇:C#程序中:如何向xml文件中写入数据和读取数据


下一篇:http权威指南笔记