Notes
- Try to break the algorithm - use special (degenerate?) test cases
错了之后想想
- debug多久了
- 是否有所线索
- 看上去错了什么类型的错误
- A short amount (20 mins) of debugging is better than switching to anything else; but you might be able to solve another from scratch in 45 mins.
- 什么时候回来做
- Consider from here out - forget prior effort, focus on the future: how can you get the most points in the next hour with what you have?
Do the Math
- 过滤,筛选,预计算,对称,
Prime Cryptarithm
暴搜一遍.
距离
一开始没看懂题意= =
环形距离
bool close(int a, int b)
{
if (abs(a-b) <= 2) return true;
if (abs(a-b) >= N-2) return true;
return false;
}
wormholes
栽在这个函数上
bool cycle_exists(void)
{
for (int start=1; start<=n; start++) {
// does there exist a cylce starting from start
int pos = start;
for (int count=0; count<n; count++)
{
pos = net[cycle[pos]];
}
if (pos != 0) return true;
}
return false;
}
- 也就是说找循环不一定要递归去找.暴力转足够次数如果还能回来就有循环了
- 另外total的统计方式也值得琢磨
语法trick
void test(){
suc=0;
for (int i=1; suc==0 && i<=n; i++)
...
tot+=suc;
}
这样不如用bool函数= =直接return
另外解决了的坑:
- 配对:
- 配对问题不能在递归函数中双重循环 这样会重复
- 不能只复原一个cycle 这样会遗漏很多
void dfs(int k,int beg){
if (k==n) {
test();
}else if(beg<n){
if (cycle[beg]) {
dfs(k,beg+1);
}else {
for (int i=1; i<=n; i++)
if (!cycle[i]&&i!=beg) {
cycle[i]=beg;
cycle[beg]=i;
dfs(k+2,beg+1);
cycle[i]=cycle[beg]=0;
}
}
}
}
(话说youtube搜usaco居然是这道题的题解视频..不过小哥为什么不说中文呢…
b站题解
Ski Course Design
一堆数据让极差<=17,修改一个数据需要
△2
费用,问最小费用
读的时候扫最大最小,再扫一遍每个数据和最大最小的差,枚举修改最小值所需要费用.
官方题解省了两个数组
for (int j=0; j<n; j++)
{
// if hill is below the interval
if (hills[j]<i)
x=i-hills[j];
// if hill is above the interval
else if (hills[j]>i+17)
x=hills[j]-(i+17);
// if hill is int the interval
else
x=0;
cost+=x*x;
}
开始涉及算法涉及啦!加油~