Informatika gyűjtemény

Egy szinttel feljebb mt_lapok.cs

2004050607080910

NézetNyomtat

mt_lapok.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: us-ascii
Méret: 2 KB
/*
 * Created by SharpDevelop.
 * User: user
 * Date: 2007.02.19.
 * Time: 14:56
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.IO;

namespace Lapok
{
    class MainClass
    {
        static int n;
        static pont[] p;
        
        public class pont:IComparable<pont>
        {
            public int x,y;
            public static bool r;
            
            public pont(int x, int y)
            {
                this.x=x;
                this.y=y;
            }
            
            public int CompareTo(pont other)
            {
                int c1, c2;
                if (r)
                {
                    c1=x;
                    c2=other.x;
                }
                else
                {
                    c1=y;
                    c2=other.y;
                }
                if (c1<c2) return -1;
                if (c1==c2) return 0;
                return 1;
            }
        }
        
        public static void Main(string[] args)
        {
            for (int i=1; i!=10; i++) csinal("lapok"+i+".be");
            Console.ReadLine();
        }
        
        public static void csinal(string inp)
        {
        
            n=0;
            p=null;
            beolvas(inp);
            
            pont[] z=p;
            int[] ind=new int[2*n];
            for (int i=0; i!=2*n; i++) ind[i]=i;
            
            pont.r=true;
            Array.Sort(p, ind);
            
            int k=p[0].x;
            int l=0;
            p[0].x=0;

            for (int i=1; i!=2*n; i++)
            {
                if (p[i].x>k)
                {
                    l++;
                    k=p[i].x;
                    p[i].x=l;
                }
                else
                {
                    p[i].x=l;
                }
            }
            
            pont.r=false;
            Array.Sort(p, ind);
            
            k=p[0].y;
            l=0;
            p[0].y=0;

            for (int i=1; i!=2*n; i++)
            {
                if (p[i].y>k)
                {
                    l++;
                    k=p[i].y;
                    p[i].y=l;
                }
                else
                {
                    p[i].y=l;
                }
            }
            Array.Sort(ind, p);

            Console.WriteLine(inp+": "+max());
        }
        
        public static int max()
        {
            int[,] t=new int[2*n,2*n];
            int m=0;
            for (int i=0; i!=n; i++) m=kitolt(t, m, p[2*i], p[2*i+1]);
            return m;
        }
        
        public static int kitolt(int[,] t, int m, pont a, pont b)
        {
            for (int i=a.x; i!=b.x+1; i++)
            {
                for (int j=a.y; j!=b.y+1; j++)
                {
                    t[i,j]++;
                    if (t[i,j]>m) m=t[i,j];
                }
            }
            return m;
        }
        
        public static void beolvas(string inp)
        {
            TextReader tr=new StreamReader(inp);
            n=Convert.ToInt32(tr.ReadLine());
            p=new pont[2*n];
            for (int i=0; i!=n; i++)
            {
                string[] l=tr.ReadLine().Split(' ');
                p[2*i]=new pont(Convert.ToInt32(l[0]), Convert.ToInt32(l[1]));
                p[2*i+1]=new pont(Convert.ToInt32(l[2]), Convert.ToInt32(l[3]));
            }
            tr.Close();
        }
    }
}
(Vissza)