做了俩,rating涨了80。第二个题是关于身份证的模拟题,写的时间比较长,但是我认真检查了。。。

第三个题是最短路,今天写了写,写的很繁琐,写的很多错。

 #include <cstring>
#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define INF 0xfffffff
vector<string>::iterator it;
int p[][];
int a[] = {,,,-};
int b[] = {,-,,};
struct node
{
int u,v,w,next;
}edge[];
int first[];
int in[],d[];
int tot;
void CL()
{
memset(first,-,sizeof(first));
tot = ;
}
void add(int u,int v,int w)
{
edge[tot].u = u;
edge[tot].v = v;
edge[tot].w = w;
edge[tot].next = first[u];
first[u] = tot ++;
}
int spfa(int x,int n,int key)
{
int i,u,v;
queue<int> que;
for(i = ;i <= n;i ++)
{
in[i] = ;
d[i] = INF;
}
in[x] = ;
d[x] = key;
que.push(x);
while(!que.empty())
{
u = que.front();
que.pop();
in[u] = ;
for(i = first[u];i != -;i = edge[i].next)
{
v = edge[i].v;
if(d[v] > d[u] + edge[i].w)
{
d[v] = d[u] + edge[i].w;
if(!in[v])
{
in[v] = ;
que.push(v);
}
}
}
}
int ans = ;
for(i = ;i <= n;i ++)
{
if(i != x)
ans = max(ans,d[i]);
}
return ans;
}
class GameOnABoard
{
public:
int optimalChoice(vector <string> cost)
{
int i,j,k,n,len,ans;
n = ;
CL();
for(it = cost.begin();it != cost.end();it ++)
{
len = ;
for(j = ;j <= (*it).size();j ++)
{
p[n][j] = (*it)[j-] - '';
len ++;
}
n ++;
}
n --;
for(i = ;i <= n;i ++)
{
for(j = ;j <= len;j ++)
{
for(k = ;k < ;k ++)
{
if(i+a[k] >= &&i + a[k] <= n&&j + b[k] >= &&j + b[k] <= len)
{
add((i-)*len+j,(i+a[k]-)*len+j+b[k],p[i+a[k]][j+b[k]]);
}
}
}
}
ans = ;
for(i = ;i <= n;i ++)
{
for(j = ;j <= len;j ++)
ans = min(ans,spfa((i-)*len+j,n*len,p[i][j]));
}
return ans;
}
};

TC SRM 583 DIV 2的更多相关文章

  1. TC SRM 584 DIV 2

    第一次在DIV2 AK了. 250水题. 500,FLoyd搞出所有边的最短路,然后找最短路,中最长的,如果有不连通的边返回-1 1000,组合DP,各种慌乱,在最后1分钟时,交上了,感觉很棒,最后还 ...

  2. SRM 583 Div II Level One:SwappingDigits

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12609 #include <iostream> # ...

  3. SRM 583 Div Level Two:IDNumberVerification

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12610 这道题比较有意思,估计是中国人出的吧,以前都不知道身份 ...

  4. SRM 583 Div II Level Three:GameOnABoard,Dijkstra最短路径算法

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12556 用Dijkstra实现,之前用Floyd算法写了一个, ...

  5. TC SRM 582 DIV 2

    Rating又跌了,第二个题,没想好就乱开始乱写了.. 我写乱搞贪心,没过...如果总人数很多judge函数写的不好,DIV2数据很水,直接暴力就行. #include <cstring> ...

  6. 【TC SRM 718 DIV 2 B】Reconstruct Graph

    [Link]: [Description] 给你两个括号序列; 让你把这两个括号序列合并起来 (得按顺序合并) 使得组成的新的序列为合法序列; 即每个括号都能匹配; 问有多少种合并的方法; [Solu ...

  7. 【TC SRM 718 DIV 2 A】RelativeHeights

    [Link]: [Description] 给你n个数字组成原数列; 然后,让你生成n个新的数列a 其中第i个数列ai为删掉原数列中第i个数字后剩余的数字组成的数列; 然后问你这n个数列组成的排序数组 ...

  8. Topcoder口胡记 SRM 562 Div 1 ~ SRM 599 Div 1

    据说做TC题有助于提高知识水平? :) 传送门:https://284914869.github.io/AEoj/index.html 转载请注明链接:http://www.cnblogs.com/B ...

  9. SRM 583 DIV1

    A 裸最短路. class TravelOnMars { public: int minTimes(vector <int>, int, int); }; vector<int> ...

随机推荐

  1. 集群高可用之lvs+keepalive

    集群高可用之lvs+keepalive keepalive简介: 负载均衡架构依赖于知名的IPVS内核模块,keepalive由一组检查器根据服务器的健康情况动态维护和管理服务器池.keepalive ...

  2. Spring Cloud 从入门到精通

    Spring Cloud 是一套完整的微服务解决方案,基于 Spring Boot 框架,准确的说,它不是一个框架,而是一个大的容器,它将市面上较好的微服务框架集成进来,从而简化了开发者的代码量. 本 ...

  3. 刷题总结——卡牌配对(bzoj4205网络流)

    题目: Description 现在有一种卡牌游戏,每张卡牌上有三个属性值:A,B,C.把卡牌分为X,Y两类,分别有n1,n2张. 两张卡牌能够配对,当且仅当,存在至多一项属性值使得两张卡牌该项属性值 ...

  4. 刷题总结——子串(NOIP2015提高组)

    题目: 题目背景 NOIP2015 提高组 Day2 T2 题目描述 有两个仅包含小写英文字母的字符串 A 和 B .现在要从字符串 A 中取出 k 个互不重叠的非空子串,然后把这 k 个子串按照其在 ...

  5. P1140 相似基因 (动态规划)

    题目背景 大家都知道,基因可以看作一个碱基对序列.它包含了4种核苷酸,简记作A,C,G,T.生物学家正致力于寻找人类基因的功能,以利用于诊断疾病和发明药物. 在一个人类基因工作组的任务中,生物学家研究 ...

  6. mysql/oracle 连接参数中文变问号

    jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=utf8&useSSL=true

  7. asp.net mvc 页面内容呈现Html.Raw HtmlString

    asp.net mvc 页面内容呈现Html.Raw Html.Raw内容经过页面呈现,不呈现Html标签 @Html.Raw( File.ReadAllText(Server.MapPath(&qu ...

  8. WMAP 启动报错 PHP- 提示缺少 msvcr110.dll 的问题

    问题描述:  启动 php-cgi 时如果提示缺少 msvcr110.dll 问题原因:  缺少 vc++ 2012 运行库    问题解决: 需要安装 vcredist_x64.exe 或 vcre ...

  9. Laravel 之文件上传

    配置文件: config/filesystems.php, 新建存储空间 'uplaods' => [ 'driver' => 'local', 'root' => storage_ ...

  10. sql 注入 及 in 注入

    原文地址: http://www.cnblogs.com/lzrabbit/archive/2012/04/22/2465313.html 除了校验参数内容,过滤长度和sql关键字. 解决in条件拼接 ...