原题链接:http://codeforces.com/gym/100203/attachments/download/1702/statements.pdf

题解

考虑暴力的复杂度是O(n^3),所以我们需要记录所有的ai+aj,如果当前考虑到了ak,那么就去前面寻找ai,使得ak-ai是我们记录过的和。整个算法的复杂度O(n^2)。

代码

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define MAX_N 5555
#define MAX_A 1000006
using namespace std; bool vis[MAX_A];
int n;
int a[MAX_N];
int ans=; int x=; int main() {
scanf("%d", &n);
for (int i = ; i < n; i++) {
scanf("%d", &a[i]); for (int j = ; j < i; j++) {
if (vis[a[i] - a[j] + * x]) {
ans++;
break;
}
}
for (int j = ; j <= i; j++)vis[a[i] + a[j] + * x] = ;
}
printf("%d\n", ans);
return ;
}

Codeforces Gym 100203G Good elements 暴力乱搞的更多相关文章

  1. VIJOS1476 旅行规划(树形Dp + DFS暴力乱搞)

    题意: 给出一个树,树上每一条边的边权为 1,求树上所有最长链的点集并. 细节: 可能存在多条最长链!最长链!最长链!重要的事情说三遍 分析: 方法round 1:暴力乱搞Q A Q,边权为正-> ...

  2. codeforces 653C C. Bear and Up-Down(乱搞题)

    题目链接: C. Bear and Up-Down time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  3. [CSP-S模拟测试]:Cicada拿衣服(暴力+乱搞)

    题目传送门(内部题94) 输入格式 第一行两个整数$n,k$,代表衣服的数量和阈值. 接下来一行$n$个数,第$i$个数$a_i$表示每件衣服的愉悦值. 输出格式 输出一行$n$个数,第$i$个数为$ ...

  4. Codeforces Gym 100203G G - Good elements 暴力

    G - Good elementsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  5. Codeforces Gym 100203G G - Good elements 标记暴力

    G - Good elementsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  6. Codeforces #254 div1 B. DZY Loves FFT 暴力乱搞

    B. DZY Loves FFT 题目连接: http://codeforces.com/contest/444/problem/B Description DZY loves Fast Fourie ...

  7. Codeforces 34C-Page Numbers(set+vector+暴力乱搞)

    C. Page Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  8. Codeforces 245G Suggested Friends 暴力乱搞

    G. Suggested Friends time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  9. Codeforces Gym 100015H Hidden Code 暴力

    Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hac ...

随机推荐

  1. SpringMVC总结以及在面试中的一些问题.

    1.简单的谈一下SpringMVC的工作流程? 流程 1.用户发送请求至前端控制器DispatcherServlet 2.DispatcherServlet收到请求调用HandlerMapping处理 ...

  2. vim中,在编辑模式下如何快速移动光标

    编辑 ~/.vimrc 配置文件,加入如下行,编辑模式下自定义的快捷键 inoremap <C-o> <Esc>o  inoremap <C-l> <Righ ...

  3. LeetCode(143) Reorder List

    题目 Given a singly linked list L: L0→L1→-→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→- You must do ...

  4. poj-3009 curling2.0(搜索)

    Curling 2.0 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 26408   Accepted: 10546 Des ...

  5. LightOj:1422-Halloween Costumes

    传送门:http://www.lightoj.com/volume_showproblem.php?problem=1422 Halloween Costumes problem descriptio ...

  6. zoj 4057

    #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> ...

  7. python--eclipse第一步总结

    1.SyntaxError: Non-UTF-8 code starting with '\xc4' in file C:\Users\yangqiong\workspace\create.报错 解决 ...

  8. EOJ Monthly 2018.1

    985月赛,当时鸽了,现在想补一补 A. 石头剪刀布的套路 Time limit per test: 1.0 seconds Memory limit: 256 megabytes 现在有一种石头剪刀 ...

  9. rabbitmq exchange type

    This is the fourth installment to the series: RabbitMQ for Windows.  In thelast installment, we revi ...

  10. 移动端(钉钉微服务)webpack配置需要移除hash来解决应用更新后白屏的问题

    钉钉微服务webpack配置调整方案 1: Vue CLI配置修改方法 a. 修改build下webpack.prod.config.js.去掉图中三处hash(.[chunkhash]): b. 修 ...