我是靠谱客的博主 细心冬日,这篇文章主要介绍Codeforces 653A Bear and Three Balls【水题】,现在分享给大家,希望可以做个参考。

题目链接:

http://codeforces.com/problemset/problem/653/A

题意:

给定序列,找是否存在连续的三个数。

分析:

排序~去重~直接判断~~

代码:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<iostream> #include<algorithm> #include<vector> using namespace std; const int maxn = 105; int t[maxn], tt[maxn], vis[1005]; int main (void) { int n;cin>>n; int a = 0; for(int i = 0; i < n; i++){ cin>>tt[i]; if(vis[tt[i]]) continue; t[a++] = tt[i]; vis[tt[i]] = 1; } sort(t, t + a); for(int i = 0; i < n - 2; i++){ if(t[i] == t[i + 1] - 1 && t[i + 2] == t[i + 1] + 1){ cout<<"YES"<<endl; return 0; } } cout<<"NO"<<endl; return 0; }

有生之年再一次A没做出来。比赛的时候就是打死也没想到去重这回事,如果做出来了,肯定不至于掉这么多分。。。。真是无语。。。
总结:多试试几组数,不能方!

转载于:https://www.cnblogs.com/Tuesdayzz/p/5758721.html

最后

以上就是细心冬日最近收集整理的关于Codeforces 653A Bear and Three Balls【水题】的全部内容,更多相关Codeforces内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(90)

评论列表共有 0 条评论

立即
投稿
返回
顶部