Gym - 100203G Good elements 水+模拟
题意:good element的定义是a[i]在1~i-1中任取三个数(可以重复)的和能等于a[i]
思路:vis[x]标记一下任两个数的和,处理a[i]时枚举1~i-1判断vis[a[i] - a[j]]是否被标记
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#define LL long long
#define eps 1e-8
#define INF 0x3f3f3f3f
#define MAXN 200005
using namespace std;
int a[];
bool vis[];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // OPEN_FILE
int n;
scanf("%d", &n);
for(int i = ; i <= n; i++){
scanf("%d", &a[i]);
}
int ans = ;
for(int i = ; i <= n; i++){
for(int j = ; j <= i - ; j++){
if(!vis[a[i] - a[j] + MAXN]) continue;
ans++;
break;
}
for(int j = ; j <= i; j++){
vis[a[i] + a[j] + MAXN] = true;
}
}
printf("%d\n", ans);
}
Gym - 100203G Good elements 水+模拟的更多相关文章
- Codeforces Gym 100203G Good elements 暴力乱搞
原题链接:http://codeforces.com/gym/100203/attachments/download/1702/statements.pdf 题解 考虑暴力的复杂度是O(n^3),所以 ...
- CodeForces.158A Next Round (水模拟)
CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...
- CodeForces.71A Way Too Long Words (水模拟)
CodeForces71A. Way Too Long Words (水模拟) 题意分析 题怎么说你怎么做 没有坑点 代码总览 #include <iostream> #include & ...
- Codeforces Gym 100203G G - Good elements 标记暴力
G - Good elementsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
- Codeforces Gym 100203G G - Good elements 暴力
G - Good elementsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
- Gym 100851E Easy Problemset (水题,模拟)
题意:给定 n 个裁判,然后每个都一些题目,现在要从每一个按顺序去选出 k 个题,并且这 k 个要按不递减顺序,如果没有,就用50补充. 析:就按他说的来,直接模拟就好. 代码如下: #pragma ...
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) A B C D 水 模拟 并查集 优先队列
A. Broken Clock time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces Gym 100269B Ballot Analyzing Device 模拟题
Ballot Analyzing Device 题目连接: http://codeforces.com/gym/100269/attachments Description Election comm ...
- Codeforces Round #374 (Div. 2) A B C D 水 模拟 dp+dfs 优先队列
A. One-dimensional Japanese Crossword time limit per test 1 second memory limit per test 256 megabyt ...
随机推荐
- 四则运算1 java+jsp+SQLServer
1,设计思想(1)在java resourse里定义包和类 (2)在类里定义生成算式,并将算式保存在数据库中的方法 (3)在jsp文件中调用java方法 2,源程序代码 生成算式的方法 public ...
- pointer-events的css属性。使用该属性可以决定是否能穿透绝对定位元素去触发下面元素的某些行为
pointer-events的css属性.使用该属性可以决定是否能穿透绝对定位元素去触发下面元素的某些行为,比如当一个元素盖住了某个点击事件时可用. 现在Firefox3.6+/Safari4+/Ch ...
- POJ——T 1422 Air Raid
http://poj.org/problem?id=1422 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8579 A ...
- iOS:UISplitViewController的创建
UISplitViewController是iPad特有的系统方法,主要效果就是呈现iPad的经典切割界面 代码创建实例: - (BOOL)application:(UIApplication *)a ...
- deque迭代器失效的困惑?
在实现LRU算法的时候lru_list 開始用的是deque 可是由于害怕其在插入删除上的迭代器失效情况的诡异情况.遂用list取代之. 在数据量比較大的时候性能不是非常好.性能优化分析的时候决定用d ...
- Android 解决TextVIew载入自己定义字体慢的问题
网上非常多自己定义字体样式的代码.都是告诉应该这样做: 在自己定义控件里写,可是这样写有问题,会随着界面里自己定义控件越多.Activity载入速度越慢,太多了easy造成内存泄露问题,由于你没创建一 ...
- 使用React Hook后的一些体会
一.前言 距离React Hook发布已经有一段时间了,笔者在之前也一直在等待机会来尝试一下Hook,这个尝试不是像文档中介绍的可以先在已有项目中的小组件和新组件上尝试,而是尝试用Hook的方式构建整 ...
- Python: PS 图像调整--颜色梯度
本文用 Python 实现 PS 中的色彩图,可以看到颜色的各种渐变,具体的效果可以参考以前的博客: http://blog.csdn.net/matrix_space/article/details ...
- PermissionError: [Errno 13] in python
出现该错误,首先尝试以管理员身份运行 cmd.exe 程序,然后关闭所有的与 python 相关的进程. 1. open 打开一个文件夹(目录),而不是文件 这一错误一般发生在使用 open函数对文件 ...
- Dictionary as a set of counters
Suppose you are given a string and you want to count how many times each letters appears. There are ...