Az alábbi letöltési lehetőségek közül választhatsz: (
segítség)
Típus: text/plain
Tartalmaz szöveget
Karakterkódolás: utf-8
Méret: 5 KB
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace Madar
{
class Set<E> : IEnumerable
{
private List<E> list;
public void Add( E item )
{
int index = list.BinarySearch(item);
if (index < 0)
{
list.Insert(~index, item);
}
}
public void AddAll( List<E> items )
{
foreach( E item in items )
{
Add( item );
}
}
public Set()
{
list = new List<E>();
}
public Set( int capacity )
{
list = new List<E>(capacity);
}
public int Count {
get {
return list.Count;
}
}
#region IEnumerable implementation
public IEnumerator GetEnumerator ()
{
return list.GetEnumerator();
}
#endregion
}
class Position : IComparable<Position>
{
public int v;
public int idx;
public int type;
#region IComparable[Madar.Position] implementation
public int CompareTo (Position other)
{
return v.CompareTo(other.v);
}
#endregion
public Position( int v, int idx, int type )
{
this.v = v;
this.idx = idx;
this.type = type;
}
}
class Bird
{
public int x1, y1, x2, y2;
public Set<int> opponents = new Set<int>();
public Bird( int y, int x, int radius, int size )
{
x1 = x-radius-1;
if( x1 < 0 ) x1 = 0;
y1 = y-radius-1;
if( y1 < 0 ) y1 = 0;
x2 = x+radius-1;
if( x2 >= size ) x2 = size-1;
y2 = y+radius-1;
if( y2 >= size ) y2 = size-1;
}
}
class Program
{
private int n, size;
private List<Bird> birds;
public Program()
{
GetTerritories();
string AandB = SolveAandB();
string C = SolveC();
StreamWriter outs = new StreamWriter("madar.ki");
outs.Write(AandB);
outs.WriteLine(C);
outs.Close();
}
public string SolveAandB()
{
Set<int>[,] land = new Set<int>[size,size];
for( int i=0; i<birds.Count; i++ ) {
for(int x = birds[i].x1; x <= birds[i].x2; x++) {
for(int y = birds[i].y1; y <= birds[i].y2; y++) {
if( land[x, y] == null ) {
land[x, y] = new Set<int>(n);
land[x, y].Add(i);
} else {
foreach( int item in land[x, y] )
{
birds[item].opponents.Add( i );
birds[i].opponents.Add( item );
}
land[x, y].Add( i );
}
}
}
}
List<int> solo = new List<int>(n);
int maxOpponent = 0, idx = -1;
for( int i=0; i<birds.Count; i++ )
{
if( birds[i].opponents.Count == 0 ) solo.Add( i+1 ); else {
if( maxOpponent < birds[i].opponents.Count ) {
maxOpponent = birds[i].opponents.Count;
idx = i;
}
}
}
StringBuilder sb = new StringBuilder();
if( solo.Count == 0 ) {
sb.AppendLine();
} else {
for( int i=0; i<solo.Count; i++ )
sb.Append(solo[i] + " ");
sb.AppendLine();
}
if( idx == -1 ) {
sb.AppendLine();
} else {
sb.AppendLine(""+(idx+1));
}
return sb.ToString();
}
public string SolveC()
{
int sum = 0;
for( int a=0; a<birds.Count; a++ ) {
for( int b=a+1; b<birds.Count; b++ ) {
if(( birds[a].x1 >= birds[b].x1 && birds[a].x2 <= birds[b].x2 &&
birds[a].y1 >= birds[b].y1 && birds[a].y2 <= birds[b].y2) ||
( birds[b].x1 >= birds[a].x1 && birds[b].x2 <= birds[a].x2 &&
birds[b].y1 >= birds[a].y1 && birds[b].y2 <= birds[a].y2)
){
sum++;
}
}
}
return ""+sum;
}
public void GetTerritories()
{
StreamReader ins = new StreamReader("madar.be");
string[] line = ins.ReadLine().Split(' ');
n = int.Parse(line[0]);
size = int.Parse(line[1]);
birds = new List<Bird>(n);
for( int i=0; i<n; i++ ) {
line = ins.ReadLine().Split(' ');
birds.Add( new Bird( int.Parse(line[0]), int.Parse(line[1]), int.Parse(line[2]), size ) );
}
List<Position> positions = new List<Position>(2*n);
Bird b;
for( int i=0; i<birds.Count; i++ ) {
b = birds[i];
positions.Add( new Position( b.x1, i, 1 ) );
positions.Add( new Position( b.x2, i, 2 ) );
}
positions.Sort();
int prevPos = positions[0].v;
int newPos = 0;
for( int i=0; i<positions.Count; i++ ) {
if( positions[i].v > prevPos ) {
newPos++;
prevPos = positions[i].v;
}
if( positions[i].type == 1 ) {
birds[ positions[i].idx ].x1 = newPos;
} else {
birds[ positions[i].idx ].x2 = newPos;
}
}
int biggestPos = newPos;
positions.Clear();
for( int i=0; i<birds.Count; i++ ) {
b = birds[i];
positions.Add( new Position( b.y1, i, 1 ) );
positions.Add( new Position( b.y2, i, 2 ) );
}
positions.Sort();
prevPos = positions[0].v;
newPos = 0;
for( int i=0; i<positions.Count; i++ ) {
if( positions[i].v > prevPos ) {
newPos++;
prevPos = positions[i].v;
}
if( positions[i].type == 1 ) {
birds[ positions[i].idx ].y1 = newPos;
} else {
birds[ positions[i].idx ].y2 = newPos;
}
}
if( biggestPos < newPos )
biggestPos = newPos;
size = biggestPos+1;
}
public static void Main(string[] args)
{
new Program();
}
}
}