Codeforces 653A C#写算法题

来源:互联网 发布:淘宝模特招聘58同城 编辑:程序博客网 时间:2024/06/15 09:23

前言

  • 就是想用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();        }    }}
0 0
原创粉丝点击