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中的设计模式及其六大原则

    设计模式分类: 一共分为3大类:创造型模式.结构型模式.行为型模式. 创造型模式:工厂方法(FactoryMethod).抽象工厂模式(AbstractFactory).建造者模式(Builder). ...

  2. debian上安装codeblocks

    1.查看linux的版本uname -a 2.在官网上下载稳定版的codeblocks(www.codeblocks.org) 3.解压codeblocks后,进入到文件夹中用root身份执行dpkg ...

  3. css中的块级和内联元素

    块级元素: 首先说明display是块级元素,会单独站一行,如 代码: <!DOCTYPE html> <html> <head lang="en"& ...

  4. KMeans的数据压缩

    import numpy as np import matplotlib.pyplot as plt from sklearn.cluster import KMeans from sklearn.u ...

  5. linux命令-xz压缩

    xz gzip bzip2使用方法基本一样 压缩文件 [root@wangshaojun ~]# xz 111.txt[root@wangshaojun ~]# ls  //////111.txt文件 ...

  6. net.sf.json-lib maven依赖问题.

    <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</art ...

  7. [cf839d]Winter is here容斥原理

    题意:给定一个数列${a_i}$,若子序列长度为$k$,最大公约数为$gcd$,定义子序列的权值为$k*\gcd (\gcd  > 1)$.求所有子序列的权值和. 答案对10^9+7取模. 解题 ...

  8. Entity Framework Code-First(9):DataAnnotations

    DataAnnotations in Code-First: EF Code-First provides a set of DataAnnotation attributes, which you ...

  9. c++中Int装string

    java中,string类型非常强大,任何类型和string类型相加都变成了string类型.但是c++中string功能就比较少 int转string有两种方式 1:stringstream; ; ...

  10. URAL 2021 Scarily interesting! (贪心+题意)

    题意:给定两个队伍的每个人的得分,让你安排怎么比赛才能使得观众知道冠军的时间最长. 析:贪心,很简单,就是先开始总分高的先出最差劲的,总分低的先出最厉害的,这个题当时实在是读的不明白啊,WA了好多次. ...