TC SRM 583 DIV 2
做了俩,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的更多相关文章
- TC SRM 584 DIV 2
第一次在DIV2 AK了. 250水题. 500,FLoyd搞出所有边的最短路,然后找最短路,中最长的,如果有不连通的边返回-1 1000,组合DP,各种慌乱,在最后1分钟时,交上了,感觉很棒,最后还 ...
- SRM 583 Div II Level One:SwappingDigits
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12609 #include <iostream> # ...
- SRM 583 Div Level Two:IDNumberVerification
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12610 这道题比较有意思,估计是中国人出的吧,以前都不知道身份 ...
- SRM 583 Div II Level Three:GameOnABoard,Dijkstra最短路径算法
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12556 用Dijkstra实现,之前用Floyd算法写了一个, ...
- TC SRM 582 DIV 2
Rating又跌了,第二个题,没想好就乱开始乱写了.. 我写乱搞贪心,没过...如果总人数很多judge函数写的不好,DIV2数据很水,直接暴力就行. #include <cstring> ...
- 【TC SRM 718 DIV 2 B】Reconstruct Graph
[Link]: [Description] 给你两个括号序列; 让你把这两个括号序列合并起来 (得按顺序合并) 使得组成的新的序列为合法序列; 即每个括号都能匹配; 问有多少种合并的方法; [Solu ...
- 【TC SRM 718 DIV 2 A】RelativeHeights
[Link]: [Description] 给你n个数字组成原数列; 然后,让你生成n个新的数列a 其中第i个数列ai为删掉原数列中第i个数字后剩余的数字组成的数列; 然后问你这n个数列组成的排序数组 ...
- Topcoder口胡记 SRM 562 Div 1 ~ SRM 599 Div 1
据说做TC题有助于提高知识水平? :) 传送门:https://284914869.github.io/AEoj/index.html 转载请注明链接:http://www.cnblogs.com/B ...
- SRM 583 DIV1
A 裸最短路. class TravelOnMars { public: int minTimes(vector <int>, int, int); }; vector<int> ...
随机推荐
- TOJ 4244: Sum
4244: Sum Time Limit(Common/Java):3000MS/9000MS Memory Limit:65536KByteTotal Submit: 63 ...
- 开源中国git关联xcode操作步骤
1.网上代码托管有好多我选了开源中国的git 2.开源中国链接:http://git.oschina.net 3.在git上创建一个新的项目 4.打开终端全局设置名字和邮箱 tanqihongdeiM ...
- BZOJ 3750: [POI2015]Pieczęć 【模拟】
Description 一张n*m的方格纸,有些格子需要印成黑色,剩下的格子需要保留白色. 你有一个a*b的印章,有些格子是凸起(会沾上墨水)的.你需要判断能否用这个印章印出纸上的图案.印的过程中需要 ...
- solr学习0
solr中文网,solr教程1,solr教程2,solr教程3 solr界面使用:文章1 windows安装solr:文章1,文章2 solr集群:文章1
- 标准C程序设计七---21
Linux应用 编程深入 语言编程 标准C程序设计七---经典C11程序设计 以下内容为阅读: <标准C程序设计>(第7版) 作者 ...
- BZOJ——1607: [Usaco2008 Dec]Patting Heads 轻拍牛头
http://www.lydsy.com/JudgeOnline/problem.php?id=1607 Time Limit: 3 Sec Memory Limit: 64 MBSubmit: 2 ...
- PHP实现INT型,SHORT型,STRING转换成BYTE数组
实现PHP实现INT型,SHORT型,STRING转换成BYTE数组的转化: class Bytes { public static function integerToBytes($val) { $ ...
- 深入GCD(三): Dispatch Sources
何为Dispatch Sources简单来说,dispatch source是一个监视某些类型事件的对象.当这些事件发生时,它自动将一个block放入一个dispatch queue的执行例程中.说的 ...
- pyv8的安装和使用:python中执行js代码
pyv8 的作用是在python中执行js代码,然后可以使用js里的变量等内容.python取得javascript里面的值.javascript取得python里面的值.python和javascr ...
- Android中的多线程编程(一)附源代码
Android中多线程编程:Handler类.Runnable类.Thread类之概念分析 1.Handler类: Handler是谷歌封装的一种机制:能够用来更新UI以及消息的发送和处理.Handl ...