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. POJ1365:质因数分解

    Prime Land Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3590   Accepted: 1623 Descri ...

  2. 【转】 Pro Android学习笔记(六四):安全和权限(1):签发apk

    目录(?)[-] Android安全模型 数字证书签发 Debug的keystore 生产unsigned的apk 为apk进行证书签发 align安装包 使用Export Wizard生成签发的ap ...

  3. IDEA 热部署 + 下载jar包放到maven中

    IDEA 热部署: 1 :  POM中加入devtools的依赖,就可以实现热部署 <dependency> <groupId>org.springframework.boot ...

  4. strdup与strndup

    strdup()函数是c语言中常用的一种字符串拷贝库函数,一般和free()函数成对出现. extern char *strdup(char *s); 头文件:string.h 功 能: 将串拷贝到新 ...

  5. uboot的relocation原理详细分析

    转自:http://blog.csdn.net/skyflying2012/article/details/37660265 最近在一直在做uboot的移植工作,uboot中有很多值得学习的东西,之前 ...

  6. VisualGDB系列1:VisualGDB总体概述

    根据VisualGDB官网(https://visualgdb.com)的帮助文档大致翻译而成.主要是作为个人学习记录.有错误的地方,Robin欢迎大家指正. 本文总体介绍VisualGDB能给你带来 ...

  7. WPF x:key和x:name用法

    WPF x:key和x:name用法 x:Key用在xaml Resources,ResourceDictionary需要key来访问 x:Name用在ResourceDictionary以外任何地方 ...

  8. position应用之相对父元素的定位

    分别添加以下style即可: 父元素position:relative; 子元素position:absolute; right:0px; bottom:0px;

  9. 第3章 机器学习的典型应用 3-4 典型应用-ctr预估和协同过滤

    ctr预估,用户点击率的预估.这个算法的名字叫ctr预估,但是它背后算法是线性的逻辑回归. 现在的推荐系统除了可能会用关联规则之外,现在还有一些所谓的更新的协同过滤的算法.

  10. Hadoop Reducer个数设置

    在默认情况下,一个MapReduce Job如果不设置Reducer的个数,那么Reducer的个数为1.具体,可以通过JobConf.setNumReduceTasks(int numOfReduc ...