暑假集训日记--8.9--搜索、图论专题总结
来源:互联网 发布:表示喜欢的网络用语 编辑:程序博客网 时间:2024/06/05 09:50
今天搜索和图论的专题就结束了。
总结一下在这一周半的学习:
首先通过做题巩固了搜索的知识。深搜和广搜也有了较大的提高。但是图论花的时间相对低。
专题只做了18个题,剩下的题会补上。
在过去的一周半里,前面还好一点,后面每写一个代码都要调试好久。有的时候一晚上都在调试一个代码。感觉时间全都用来调代码了。我觉得这也反映了一个问题,就是基础知识的不牢固以及理解的还不够深刻。
这一套专题有很多人AK了。感觉自己好菜……唉还是功夫不到家吧。
明天好像就要开始新的专题了,单调队列和二分。
今天复习了一下二分的知识。印象当中好像二分学的还可以。。。
然后看了看单调队列。
下面对单调队列做一个简单的理解总结:
单调队列是队首和队尾都可以进行出队操作,在队尾进行入队操作。
若新插入的元素从队尾插入后会破坏单调性,删除队尾元素,直到不破坏单调性为止,将其插入单调队列。
既然是单调队列,那么获取最大值或者最小值就可以访问队首或者队尾元素。
自己考虑了一下:
基本上代码就这样:
int head = 1,tail = 0;
for (在输入的数的个数里)
{
输入元素。
while(head <= tail && 新插入的元素和tail位置元素进行比较)
若不满足条件则tail--;
直到满足条件,将元素插入。
}
今天看了几道例题,还有记录路径的问题。有很多,在接下来的专题训练中可以去加深巩固,然后继续学习。
努力的补知识点:新的一周还是要努力看书。这一周看书有点少说实话。要多看课件,例题,然后书。
同时在学算法学累了的时候,空闲时间可以看看《c++ primer》。争取这个假期看完一遍。
上一周的表现确实让人不太满意。
下一个专题,继续努力。
争取可以AK。
附今天做的一道最小生成树的题:
Today, ACM is rich enough to pay historians to study its history. One thing historians tried to find out is so called derivation plan -- i.e. how the truck types were derived. They defined the distance of truck types as the number of positions with different letters in truck type codes. They also assumed that each truck type was derived from exactly one other truck type (except for the first truck type which was not derived from any other type). The quality of a derivation plan was then defined as
where the sum goes over all pairs of types in the derivation plan such that to is the original type and td the type derived from it and d(to,td) is the distance of the types.
Since historians failed, you are to write a program to help them. Given the codes of truck types, your program should find the highest possible quality of a derivation plan.
4aaaaaaabaaaaaaabaaaaaaabaaaa0
The highest possible quality is 1/3.
一道很基础的最小生成树的问题。
附源代码:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <stdio.h>
#include <string>
using namespace std;
int map[10000][10000];
int dis[10000],visit[10000];
int n,i,j;
struct Str
{
string a;
}str[10000];
int get(int i,int j)
{
int sum = 0;
for (int t = 0; t < 7; t++)
{
if (str[i].a[t] != str[j].a[t])
sum++;
}
return sum;
}
int main()
{
while (scanf("%d",&n) != EOF)
{
if (n == 0)
break;
for (i = 1; i <= n; i++)
cin >> str[i].a;
for (i = 1; i <= n - 1; i++)
{
for (j = i + 1; j <= n; j++)
{
map[i][j] = get(i,j);
map[j][i] = get(j,i);
}
}
memset(visit,0,sizeof(visit));
for (int t = 1; t <= n; t++)
dis[t] = map[1][t];
visit[1] = 1;
int flag,sum = 0;
for (int t = 1; t <= n - 1; t++)
{
int minn = 100000;
for (int p = 1; p <= n; p++)
{
if (!visit[p] && dis[p] < minn)
{
minn = dis[p];
flag = p;
}
}
visit[flag] = 1;
sum += dis[flag];
for (int p = 1; p <= n; p++)
{
if (!visit[p] && dis[p] > map[flag][p])
dis[p] = map[p][flag];
}
}
cout << "The highest possible quality is 1/" << sum <<"."<< endl;
}
return 0;
}
- 暑假集训日记--8.9--搜索、图论专题总结
- 【暑假集训专题#搜索】
- 2014暑假集训搜索专题
- 【暑假集训专题#搜索 HDU1241】
- 暑假集训日记--7.31--搜索
- 暑假集训日记--8.2--搜索
- 暑假集训日记--8.3--搜索
- 暑假集训日记--8.4--搜索
- 暑假集训日记--8.5--搜索
- 暑假集训日记--8.7--搜索+图论
- 暑假集训日记--8.8--搜索+练习赛
- 2017.8.9暑假集训第十天(+搜索图论总结)
- 暑假集训-搜索
- 暑假集训-基础图论
- 暑假集训总结
- CCNU_2014_ACM暑假集训总结
- 暑假集训总结
- 2014暑假集训总结
- go语言开发必备
- PHP对接微信公众平台消息接口开发流程详解及实例(一)
- JAVA枚举(高级)
- android service的使用与理解
- 笨办法学 Python · 续 练习 22:后缀数组
- 暑假集训日记--8.9--搜索、图论专题总结
- The fish and bird-另类关系
- 图的基本存储的基本方式二
- MySQL语句大全
- Python模块之codecs
- linux系统调用过程解析(基于ARM处理器)
- 关于回滚段导致的ORA-01555错误
- 【C++】C++起步遇到的问题
- 【C#】B窗体关闭时刷新A窗体的DataGridView