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> ...
随机推荐
- day02-菜单处理
解决力度到按钮的级别 ----------------------------------------------------------------------------------------- ...
- SpringBoot + Spring Security 基本使用及个性化登录配置详解
Spring Security 基本介绍 这里就不对Spring Security进行过多的介绍了,具体的可以参考官方文档 我就只说下SpringSecurity核心功能: 认证(你是谁) 授权(你能 ...
- android悬浮窗口的一些说明
1.xml文件里的权限申请 <uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW" ...
- net8:XML的读写操作【广告控件的XML文件实例】
原文发布时间为:2008-08-05 -- 来源于本人的百度文章 [由搬家工具导入] 【用了datalist控件,datalist控件自己学会,主要知道其他按钮COMMANDNAME属性应该改为edi ...
- css,世界上没有绝对简单的事情
引文 自从学了前端的基础,自认为是没什么css是能难倒我的,可是事实是,世界上没有绝对简单的事情,实际上还有好多的东西等待我们去发掘. 详解 1.有些浏览器不完全支持css3,现在可以用 modern ...
- omcat 7 的domain域名配置,Tomcat 修改JSESSIONID
https://blog.csdn.net/catoop/article/details/64581325
- 社区发现(Community Detection)算法
作者: peghoty 出处: http://blog.csdn.net/peghoty/article/details/9286905 社区发现(Community Detection)算法用来发现 ...
- LightOJ1234 Harmonic Number 调和级数求和
[题目] [预备知识] ,其中r是欧拉常数,const double r= 0.57721566490153286060651209; 这个等式在n很大 的时候 比较精确. [解法]可以在 n较小的时 ...
- STM32 GPIO寄存器 IDR ODR BSRR BRR
IDR是查看引脚电平状态用的寄存器,ODR是引脚电平输出的寄存器 下面内容的原文:http://m646208823.blog.163.com/blog/static/1669029532012931 ...
- VMware 虚拟机下载链接
VMware 14 链接: https://pan.baidu.com/s/1mBeyX2Z6hGpbFc8_UC-sEw 提取码: 462t 密钥:AA510-2DF1Q-H882Q-XFPQE-Q ...