Codeforces Round #371 (Div. 2) B

传送门

题意:给你串数字 任意你取一个x 对某些数进行加x 某些数进行减x操作 是否能使得数组内的数全部相等

ps:某些数里的某些可能为0

思路:先排序 然后确定数组内有多少不同的数 大于3一定不能 小于2一定能 坑点在等于3 当数组里的数成等差数列时可以 否则不可以 例如:1 4 7 x=3; 1+3 = 4; 7-3 = 4; 1 3 4 就不可以了

AC代码:

 1 #include "iostream"
 2 #include "string.h"
 3 #include "stack"
 4 #include "queue"
 5 #include "map"
 6 #include "algorithm"
 7 #include "stdio.h"
 8 #include "math.h"
 9 #define ll long long
10 #define mem(a) memset(a,0,sizeof(a))
11 #define max(a,b) a > b ? a : b
12 #define min(a,b) a < b ? a : b
13
14 using namespace std;
15
16 int main()
17 {
18     int n,i,flag=0,a[100005],b[5];
19     cin>>n;
20     for(i=0; i<n; i++)
21         cin>>a[i];
22     sort(a,a+n);
23     b[0] = a[0];
24     int k = 1;
25     for(i=0; i<n-1; i++)
26     {
27         if(a[i+1]!=a[i])
28             b[k++] = a[i+1];
29     }
30     if(k > 3)
31         printf("NO\n");
32     else if(k==1 || k==2)
33         printf("YES\n");
34     else
35     {
36         if(b[1]-b[0] == b[2]-b[1])
37             printf("YES\n");
38         else
39             printf("NO\n");
40     }
41    return 0;
42 }
时间: 2024-08-29 13:05:36

Codeforces Round #371 (Div. 2) B的相关文章

Codeforces Round #371 (Div. 1)

A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给出的01序列相等(比较时如果长度不等各自用0补齐) 题解: 1.我的做法是用Trie数来存储,先将所有数用0补齐成长度为18位,然后就是Trie的操作了. 2.官方题解中更好的做法是,直接将每个数的十进制表示中的奇数改成1,偶数改成0,比如12345,然后把它看成二进制数10101,还原成十进制是2

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

题目链接:http://codeforces.com/problemset/problem/714/B 题目大意: 第一行输入一个n,第二行输入n个数,求是否能找出一个数x,使得n个数中的部分数加上x或部分数减去x ,n个数相等. 例如:5 1 3 3 2 1 输出: YES Init: x=1 情况,第一个数和最后一个数+x,第二三个数减去x ,则这n个数都为2(相等),故输出“YES” 解题思路: 对于刚才举的例子 可知 n个数只有三个元素 1 2 3 只要使得 2-1==3-2 即可满足条

Codeforces Round #371 (Div. 1) D. Animals and Puzzle 二维倍增

D. Animals and Puzzle 题目连接: http://codeforces.com/contest/713/problem/D Description Owl Sonya gave a huge lake puzzle of size n × m to hedgehog Filya as a birthday present. Friends immediately started to assemble the puzzle, but some parts of it turn

Codeforces Round #371 (Div. 2) C

传送门  map或者字典数的应用 简单题 题意: 思路: AC代码: 1 #include<iostream> 2 #include<cstring> 3 #include<cmath> 4 #include<map> 5 #include<algorithm> 6 #include<cstdio> 7 #define max(a,b) a>b?a:b 8 #define F(i,a,b) for(int i=a;i<=b

Codeforces Round #371 (Div. 2) A

传送门 题意: 思路: AC代码: 1 #include "iostream" 2 #include "string.h" 3 #include "stack" 4 #include "queue" 5 #include "map" 6 #include "algorithm" 7 #include "stdio.h" 8 #include "math.h&

Codeforces Round #371 (Div. 2) C. Sonya and Queries(字典树)

题目戳这 题意:给你一个数字 n ,然后 n 组输入,如果第一个字符是+,就把后面的那个数字加入到集合里面去,如果第一个字符是减号,就把后面的那个数字从集合里面去掉一个,如果是问好,就开始配对,看看有多少个数字是和问号后面的数字是匹配的,是否配对的规则是,问好后面的数字都是二进制,一表示奇数,零表示偶数,如果集合中的数字长度和二进制的输入长度不一样,就把短的那个在前面加零,比如,二进制是101,集合中的数字是12,那就是101和012匹配,如果二进制是11,集合中的数字是12345,那么就是00

Codeforces Round #371 (Div. 1) D - Animals and Puzzle 二维ST表 + 二分

D - Animals and Puzzle #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PII pair<int, int> #define PLI pair<LL, int> #define ull unsigned long long using namespace std; const in

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i