下午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,等学会了再来分析好了。。。

> aggbug.ashx?id=49f830bb-5f7e-4bff-af50-1aee1c85368b

Ecogiser's Blog

转载于:https://www.cnblogs.com/ecogiser/archive/2006/06/08/477619.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值