B. Filya and Homework
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的更多相关文章
- Codeforces Round #371 (Div. 2) B. Filya and Homework 水题
B. Filya and Homework 题目连接: http://codeforces.com/contest/714/problem/B Description Today, hedgehog ...
- 【31.95%】【CF 714B】Filya and Homework
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- Codeforces Round #371 (Div. 2)B. Filya and Homework
题目链接:http://codeforces.com/problemset/problem/714/B 题目大意: 第一行输入一个n,第二行输入n个数,求是否能找出一个数x,使得n个数中的部分数加上x ...
- Codeforces 714B. Filya and Homework
题目链接:http://codeforces.com/problemset/problem/714/B 题意: 给你一个含有 n 个数的数组, 问你是否存在一个 x, 使得这个数组中的某些数加上 x, ...
- 【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 ...
- CodeForces-714B-Filya and Homework+思路
Filya and Homework 题意: 给定一串数字,任选一个数a,把若干个数加上a,把若干个数减去a,能否使得数列全部相同: 思路: 我开始就想找出平均数,以为只有和偶数的可以,结果wa在 1 ...
- Codeforces水题集合[14/未完待续]
Codeforces Round #371 (Div. 2) A. Meeting of Old Friends |B. Filya and Homework A. Meeting of Old Fr ...
- 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 ...
- 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 ...
随机推荐
- 问题5:如何快速找到多个字典中的公共键(key)
方法一:for in循环 from random import randint, sample a1 = {k; randint(1, 4) for k in 'abcdefg'} a2 = {k; ...
- java代码Math.sqrt
总结:这个判断小数的题目,当时全只2有一个人想出了结果.老师很开心.我很桑心~~~~ 我没想到要取膜,我只想到了除以等于0就够了.至于中间的“取膜”,我没凑齐来,还是不够灵活 package com. ...
- VMware VirtualCenter Server service fails to start with the vpxd.log error: ODBC error: (28000) (1017688)
Symptoms If you experience an ungraceful shutdown of the database (for example, because of a power o ...
- Android中EditTex焦点设置和弹不弹出输入法的问题(转)
今天编程碰到了一个问题:有一款平板,打开一个有EditText的Activity会默认弹出输入法.为了解决这个问题就深入研究了下android中焦点Focus和弹出输入法的问题.在网上看了些例子都不够 ...
- centos7 firewalld使用
转 http://blog.csdn.net/jamesge2010/article/details/52449678 1.firewalld的基本使用 启动: systemctl start fir ...
- MS SQL update set select
有张表a,已经有数据 再有张表b,也已查询出数据 两张表有外键关联 需求如下: 更新表a中的某个字段,这个字段要加上(都是int型的数据)对应表b中的数据作为更新的最终数据 )) from #libL ...
- JS设置cookie、读取cookie、删除cookie(转)
JS设置cookie.读取cookie.删除cookie 转载 2015-04-17 投稿:hebedich 我要评论 Js操作Cookie总结(设置,读取,删除),工作中经常会用到的哦! ...
- sklearn有关参数
from sklearn import datasets from sklearn.linear_model import LinearRegression import matplotlib.pyp ...
- 什么是消息循环,一个简单的win32程序如何运行?
预备知识 1.什么是句柄? (HANDLE) 在win32编程中有各种句柄,那么什么是句柄呢? #define DECLARE_HANDLE(name) struct name##_ { int un ...
- linux 统计 程序 运行时间
测试 代码运行时间 linux 中的 <sys/time.h> 中 有个函数可以获取当前时间,精确到 微秒 ----> gettimeofday() #include <sy ...