做了俩,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. [luoguP3413] SAC#1 - 萌数(数位DP)

    传送门 gtm的数位dp! 看到好多题解,都是记忆化搜索,好像非常方便啊,但是我还是用递推好了,毕竟还是有些类似数位dp的题用递推的思路,记忆化做不了,现在多培养一下思路 首先这道题, 只看长度大于等 ...

  2. 算法复习——高斯消元(ssoi)

    题目: 题目描述 Tom 是个品学兼优的好学生,但由于智商问题,算术学得不是很好,尤其是在解方程这个方面.虽然他解决 2x=2 这样的方程游刃有余,但是对于下面这样的方程组就束手无策了.x+y=3x- ...

  3. bzoj 1818 Cqoi2010 内部白点 扫描线

    [Cqoi2010]内部白点 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1126  Solved: 530[Submit][Status][Disc ...

  4. spring aop在mvc的controller中加入切面无效

    spring aop在mvc的controller中加入切面无效 因为MVC的controller,aop默认使用jdk代理.要使用cglib代理. 在spring-mybatis.xml配置文件中加 ...

  5. uva 10692 高次幂取模

    Huge Mod Input: standard input Output: standard output Time Limit: 1 second The operator for exponen ...

  6. poj 3692 Kindergarten

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6956   Accepted: 3436 Desc ...

  7. ElasticSearch集群状态查看命令大全

    Elasticsearch中信息很多,同时ES也有很多信息查看命令,可以帮助开发者快速查询Elasticsearch的相关信息. _cat $ curl localhost:9200/_cat =^. ...

  8. ajax 分页(jquery分页插件pagination) 小例1

    <link rel="stylesheet" href="/plugins/jQuery/page/pagination.css"/> <sc ...

  9. hdu4888 多校B 最大流以及最大流唯一判断+输出方案

    题意,给一个矩阵,告诉你每行和.每列和,并且限制所填数不大于k,问矩阵是否唯一. 经典建图不说了,第一次遇到判断最大流唯一性的,学习了:用dfs来判断残网中是否还存在环,若存在,则表明绕这个环走一圈, ...

  10. [bzoj3709][PA2014]Bohater_贪心

    bzoj-3709 PA-2014 Bohater 题目大意:在一款电脑游戏中,你需要打败n只怪物(从1到n编号).为了打败第i只怪物,你需要消耗d[i]点生命值,但怪物死后会掉落血药,使你恢复a[i ...