下午7点 topcoder SRM 306

http://www.topcoder.com/tc?module=MatchDetails&rd=9986

好久没有做题了,不是时间不好,就是有事不在。。。

//太郁闷了,居然一道题都没有做出来,最后发现45%的人都是0分,还有一些欣慰
以下分析了petr大牛的解决方案,他居然在23分钟把三个题做完了!!!

1:BifidSortMachine
Problem Statement
Solution:
using System;
using System.Collections.Generic;
using System.Text;

namespace googlecodejam
{
public class BifidSortMachine
{
public int countMoves(int[] a)
{
int[] b = (int[])a.Clone();
Array.Sort(b);
Dictionary<int, int> d = new Dictionary<int, int>();
for (int i = 0; i < b.Length; ++i)
d[b[i]] = i;//各个元素在第几个
for (int i = 0; i < a.Length; ++i)
a[i] = d[a[i]];
int[] mx = new int[a.Length];
int r = 0;
for (int i = 0; i < a.Length; ++i)
{
///求最大递增长度,这里的递增不一定连个数字连在一起,但是必须是只增加1的,
///比如:1,2,4,5,3的最大递增长度是3,因为1,2,...3是递增的
int m = 0;
for (int j = 0; j < i; ++j)
if (a[j] == a[i] - 1)
m = Math.Max(m, mx[j]);
mx[i] = m + 1;
r = Math.Max(r, mx[i]);
}
return a.Length - r;
}
}
}

2.LightSwitches
Problem Statement
Solution:

using System;

namespace googlecodejam
{
public class LightSwitches
{
public long countPossibleConfigurations(string[] switches)
{
int n = switches.Length;
int m = switches[0].Length;
bool[,] a = new bool[n, m];
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j)
a[i, j] = switches[i][j] == 'Y';
bool[] used = new bool[n];
long res = 1;
for (int i = 0; i < m; ++i)
{
for (int j = 0; j < n; ++j)
if (!used[j] && a[j, i])//如果switch没有use,并且这里有Y
{
used[j] = true;
for (int k = 0; k < n; ++k)
if (a[k, i] && k != j)//其他行的这一列也有Y
for (int l = 0; l < m; ++l)
a[k, l] ^= a[j, l];//把那一行的所有元素 ^= 本行的所有元素
res <<= 1;
break;
}
}
return res;
}

}
}

3.TourCounting
这个题是图论相关的,没有学过,代码都看不懂!_Q,等学会了再来分析好了。。。

>

Ecogiser's Blog
posted on 2006-06-08 15:12  Binary Race  阅读(658)  评论(1编辑  收藏  举报