poj2549 Sumsets
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 11886 | Accepted: 3273 |
Description

Input
Output
Sample Input
5
2
3
5
7
12
5
2
16
64
256
1024
0
Sample Output
12
no solution
Source
#include <cstdio>
#include <map>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int mod = ; int n,a[],head[],nextt[],X[],Y[],w[],tot = ;
bool flag = false; void add(int x,int y)
{
int temp = (((x + y) % mod) + mod) % mod;
X[tot] = y;
Y[tot] = x;
nextt[tot] = head[temp];
head[temp] = tot++;
} bool query(int x,int y)
{
int temp = (((x - y) % mod) + mod) % mod;
for (int i = head[temp]; i + ; i = nextt[i])
if (X[i] != y && Y[i] != x && (X[i] + Y[i]) == (x - y) && X[i] != x && Y[i] != y)
return true;
return false;
} int main()
{
while (scanf("%d",&n) != EOF && n)
{
flag = false;
tot = ;
memset(head,-,sizeof(head));
memset(X,,sizeof(X));
memset(Y,,sizeof(Y));
for (int i = ; i <= n; i++)
scanf("%d",&a[i]);
sort(a + ,a + + n);
for (int i = ; i <= n; i++)
for (int j = i + ; j <= n; j++)
add(a[i],a[j]);
for (int i = n; i >= ; i--)
{
for (int j = i - ; j >= ; j--)
if (query(a[i],a[j]))
{
flag = ;
printf("%d\n",a[i]);
break;
}
if (flag)
break;
}
if (!flag)
puts("no solution");
} return ;
}
poj2549 Sumsets的更多相关文章
- poj 折半搜索
poj2549 Sumsets 题目链接: http://poj.org/problem?id=2549 题意:给你一个含有n(n<=1000)个数的数列,问这个数列中是否存在四个不同的数a,b ...
- POJ2549:Sumsets——题解
http://poj.org/problem?id=2549 题目大意:从集合中找到四个不相同的数,满足a+b+c=d,输出最大的d. —————————————————————————— 该式子变为 ...
- POJ 2229 Sumsets
Sumsets Time Limit: 2000MS Memory Limit: 200000K Total Submissions: 11892 Accepted: 4782 Descrip ...
- HDU 2709 Sumsets(递推)
Sumsets http://acm.hdu.edu.cn/showproblem.php?pid=2709 Problem Description Farmer John commanded his ...
- POJ 2549 Sumsets
Sumsets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10593 Accepted: 2890 Descript ...
- hdu 2709 Sumsets
Sumsets Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- poj 2220 Sumsets
Sum ...
- BZOJ1677: [Usaco2005 Jan]Sumsets 求和
1677: [Usaco2005 Jan]Sumsets 求和 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 570 Solved: 310[Submi ...
- Sumsets(POJ 2229 DP)
Sumsets Time Limit: 2000MS Memory Limit: 200000K Total Submissions: 15293 Accepted: 6073 Descrip ...
随机推荐
- 【转】: 塞尔达组在GDC2017演讲的文字翻译:技术的智慧
大家好,我是堂田卓宏,在<荒野之息>的制作中我担任技术总监的职位.我在2003年加入任天堂,并且作为程序员参与了许多不同游戏的制作.在本次的制作的过程中,我们的程序员团队也需要打破许多游戏 ...
- openstack-r版(rocky)搭建基于centos7.4 的openstack swift对象存储服务 二
openstack-r版(rocky)搭建基于centos7.4 的openstack swift对象存储服务 一 openstack-r版(rocky)搭建基于centos7.4 的openstac ...
- RNN: Feed Forward, Back Propagation Through Time and Truncated Backpropagation Through Time
原创作品,转载请注明出处哦~ 了解RNN的前向.后向传播算法的推导原理是非常重要的,这样, 1. 才会选择正确的激活函数: 2. 才会选择合适的前向传播的timesteps数和后向传播的timeste ...
- org.apache.poi版本问题
问题描述: 今天跑一段历史代码,发现不能启动,抛出java.lang.NoSuchFieldError: RETURN_NULL_AND_BLANK 问题 解决办法: 把org.apache.poi的 ...
- 重构:越来越长的 switch ... case 和 if ... else if ... else
在代码中,时常有就一类型码(Type Code)而展开的如 switch ... case 或 if ... else if ... else 的条件表达式.随着项目业务逻辑的增加及代码经年累月的修改 ...
- 《Linux内核与分析》第六周
20135130王川东 1.操作系统的三大管理功能包括:进程管理,内存管理,文件系统. 2. Linux内核通过唯一的进程标识PID来区别每个进程.为了管理进程,内核必须对每个进程进行清晰的描述,进程 ...
- U盘安装OSX
1.插入U盘,磁盘工具,格式化U盘为Mac OS X拓展 (日志式): 2.去网站搜索recovery disk assistant,此文件大约1.1M,直接打开使用它制作启动盘,进度条完毕就完成了. ...
- P4 Runtime和p4 info
p4runtime P4 Runtime是一套基于Protobuf以及gRPC框架上的协议,通过P4runtime,SDN控制器可以控制能够支援p4的设备. p4runtime当前由p4 API wo ...
- lintcode-418-整数转罗马数字
418-整数转罗马数字 给定一个整数,将其转换成罗马数字. 返回的结果要求在1-3999的范围内. 说明 什么是 罗马数字? https://en.wikipedia.org/wiki/Roman_n ...
- prototype.js中Function.prototype.bind方法浅解
prototype.js中的Function.prototype.bind方法: Function.prototype.bind = function() { var __method = this; ...