您的位置:首页 > 编程语言 > C#

Codeforces 653A C#写算法题

2016-04-13 14:28 288 查看

前言

就是想用c#实现一个网络流算法,但是怕有问题,又懒得手写测试(喂)。。。所以就想在codeforces上过点模板题试试。。

但是从没有交过c#的题,这次就写个水题试一试。。感觉c#写题好麻烦。。

题意

给你n个数,问你存在不存在3个连续的数

思路

hash一下,然后遍历所有hash值,连续3个不为0就yes

实现

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DTATest
{
class Program
{
static List<int> array = new List<int>(1005);
static void Main(string[] args)
{
for (int i = 0; i <= 1004; i++)
array.Add(0);
int n =Int32.Parse(Console.ReadLine());
String str = Console.ReadLine();
var input = str.Split(' ');
foreach (var iter in input)
{
array[Int32.Parse(iter)]++;
}
bool flag = false;
for (int i = 0; i < 1000;i++ )
{
if (array[i] > 0  && array[i + 1] > 0 && array[i + 2] > 0)
{
Console.WriteLine("Yes");
flag = true;
break;
}
}
if (!flag)
Console.WriteLine("No");

Console.Read();

}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: