http://codeforces.com/contest/714/problem/B

给定一个序列,对于每一个元素,只能 + 或者 - 一个数val。这个数一旦选定,就不能改。

问能否变成全部数字都一样。

一开始还以为没 + 一次,就要 - 一次。 结果不是,一直wa

那么这样的话,这题的正解是观察法。也可以证明。

①、全部数字都一样、有两个不同数字、三个不同数字(a[1] + a[3] =  2 * a[2])这些都易懂

那4个不同数字为什么是no呢

可以想象成找不到一个点,作为圆心,包含另外3个点(这3点在一直线)。

所以对于有三个不同数字那个,其实就是判断是否为圆心。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = + ;
int a[maxn];
int n;
LL val;
set<int> ss;
void work() {
cin >> n;
LL sum = ;
for (int i = ; i <= n; ++i) {
scanf("%d", &a[i]);
sum += a[i];
ss.insert(a[i]);
}
// sort(a + 1, a + 1 + n);
if (ss.size() == || ss.size() == ) {
printf("YES\n");
return ;
} else if (ss.size() >= ) {
printf("NO\n");
return ;
} else {
int now = ;
for (set<int> :: iterator it = ss.begin(); it != ss.end(); ++it) {
a[++now] = *it;
}
if (a[] + a[] == * a[]) {
printf("YES\n");
return ;
}
printf("NO\n");
}
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
work();
return ;
}

B. Filya and Homework的更多相关文章

  1. Codeforces Round #371 (Div. 2) B. Filya and Homework 水题

    B. Filya and Homework 题目连接: http://codeforces.com/contest/714/problem/B Description Today, hedgehog ...

  2. 【31.95%】【CF 714B】Filya and Homework

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  3. Codeforces Round #371 (Div. 2)B. Filya and Homework

    题目链接:http://codeforces.com/problemset/problem/714/B 题目大意: 第一行输入一个n,第二行输入n个数,求是否能找出一个数x,使得n个数中的部分数加上x ...

  4. Codeforces 714B. Filya and Homework

    题目链接:http://codeforces.com/problemset/problem/714/B 题意: 给你一个含有 n 个数的数组, 问你是否存在一个 x, 使得这个数组中的某些数加上 x, ...

  5. 【39.68%】【CF 714 C】Filya and Homework

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  6. CodeForces-714B-Filya and Homework+思路

    Filya and Homework 题意: 给定一串数字,任选一个数a,把若干个数加上a,把若干个数减去a,能否使得数列全部相同: 思路: 我开始就想找出平均数,以为只有和偶数的可以,结果wa在 1 ...

  7. Codeforces水题集合[14/未完待续]

    Codeforces Round #371 (Div. 2) A. Meeting of Old Friends |B. Filya and Homework A. Meeting of Old Fr ...

  8. Codeforces Round #371 (Div. 2)(set\unique)

    B. Filya and Homework time limit per test 1 second memory limit per test 256 megabytes input standar ...

  9. Codeforces Round #371 (Div. 2) A ,B , C 水,水,trie树

    A. Meeting of Old Friends time limit per test 1 second memory limit per test 256 megabytes input sta ...

随机推荐

  1. java 代码。= -=

    package com.da; //toString()方法, //Object类重写... public class ty { private String name; private int ag ...

  2. springMVC绑定json参数之二(2.2.3)

    二.springmvc 接收不同格式的json字符串 4).格式四:json传递复杂对象(对象中有属性,还有List) 复杂对象: package testVO; import java.util.L ...

  3. Redis IRedisTypedClient

    IRedisTypedClient IRedisTypedClient类相当于IRedicClient的强类型版,其方法与属性大多数与IRedisClient类似. 它支持在Redis中使用Linq查 ...

  4. LAMP 1.4 PHP编译安装

    1.下载                                                                                                 ...

  5. J2EE 工作中注意事项

    [转载于http://www.cnblogs.com/hemingwang0902/archive/2012/01/06/2314215.html] 根据当前项目中代码存在的一些问题,编写了一个编码注 ...

  6. vue的安装配置

    1.访问vue的官网: https://cn.vuejs.org/v2/guide/installation.html安装配置 2.安装淘宝镜像项目搭建 .安装node  到官网下载安装.  (中)h ...

  7. macOS 安装 Docker

    系统要求 Docker for Mac 要求系统最低为 macOS 10.10.3 Yosemite,或者 2010 年以后的 Mac 机型,准确说是带 Intel MMU 虚拟化的,最低 4GB 内 ...

  8. 业务逻辑:完成基于CRM地址完全匹配的自动分单业务逻辑

    思路: 后台系统的业务接口服务处理接收到的数据并使用Webservice技术来远程调用CRM系统的业务接口服务来进行定区的查询操作,随后从该定区中匹配一个快递员来分配工单并发送短信通知取件 操作步骤: ...

  9. RStudio版本管理 整合Git

    本文为原创,转载注明出处. 系统环境: win7 x64 R-3.1.0-win.exe RStudio-0.98.507.exe 前置条件:必须拥有github仓库: 如:https://githu ...

  10. Lucene.net 搜索引擎的中文资料

    以下是我找到的网上一些关于Lucene.net 搜索引擎的介绍资料 https://code.i-harness.com/zh-CN/tagged/lucene?page=5 http://jingp ...