Informatika gyűjtemény

Egy szinttel feljebb mt_szaruman.cs

2004050607080910

NézetNyomtat

mt_szaruman.cs (Vissza)
Az alábbi letöltési lehetőségek közül választhatsz: (segítség)
Karakterkódolás:
Sortörés:
Típus: text/plain
Tartalmaz szöveget
Karakterkódolás: utf-8
Méret: 1 KB
/*
 * Készítette a SharpDevelop.
 * Felhasználó: 02cmezei
 * Dátum: 2008.02.18.
 * Ido: 15:17
 * 
 * A sablon megváltoztatásához használja az Eszközök | Beállítások | Kódolás | Szabvány Fejlécek Szerkesztését.
 */
using System;
using System.IO;
using System.Collections.Generic;

namespace Szaruman
{
    class Program
    {
        public class Problem
        {
            public int r;
            public int[] t;
            public int mo;
        }
        static Problem p;
        static List<Problem> problems=new List<Problem>();

        public static void Munka(Problem p)
        {
            Array.Sort(p.t);
            
            int ev=-1;
            p.mo=0;
            for (int i=0; i!=p.t.Length; i++)
            {
                int m=Find(ev, i);
                if (m==-1) continue;
                ev=m;
                p.mo++;             
            }
        }
        
        public static int Find(int ev, int m)
        {
            if (ev>=p.t[m]) return -1;
            for(int i=m; i!=p.t.Length; i++)
            {
                if (p.t[i]-p.r>p.t[m]) return p.t[i-1]+p.r;
            }
            return p.t[p.t.Length-1]+p.r;
        }
        
        public static void Main(string[] args)
        {
            Beolvas("army.in");
            for (int i=0; i!=problems.Count; i++)
            {
                p=problems[i];
                Munka(p);
            }
            Kiir("army2.out");
        }
        
        public static void Kiir(string outp)
        {
            TextWriter tw=new StreamWriter(outp);
            for (int i=0; i!=problems.Count; i++) tw.WriteLine(problems[i].mo);
            tw.Close();
        }
        
        public static void Beolvas(string inp)
        {
            TextReader tr=new StreamReader(inp);
            string[] l;
            while((l=tr.ReadLine().Split(' '))[0]!="-1")
            {
                Problem p=new Problem();
                p.r=int.Parse(l[0]);
                p.t=new int[int.Parse(l[1])];
                
                l=tr.ReadLine().Split(' ');
                for (int i=0; i!=p.t.Length; i++) p.t[i]=int.Parse(l[i]);
                problems.Add(p);
            }
            tr.Close();
        }
    }
}
(Vissza)