题目:http://community.topcoder.com/stat?c=problem_statement&pm=13090

参考:http://apps.topcoder.com/wiki/display/tc/SRM+615?decorator=printable

转换为最短路径模型这一步挺难想的.

代码:

#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <iostream>
#include <sstream>
#include <iomanip>#include <bitset>
#include <string>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;#define CHECKTIME() printf("%.2lf\n", (double)clock() / CLOCKS_PER_SEC)
typedef pair<int, int> pii;
typedef long long llong;
typedef pair<llong, llong> pll;
#define mkp make_pair/*************** Program Begin **********************/
int g[51][51];
long long dist[20001][51];
const long long INF = 0x7f7f7f7f7f7f7f7f;class LongLongTripDiv1 {
public:string isAble(int N, vector <int> A, vector <int> B, vector <int> D, long long T) {memset(g, 0, sizeof(g));memset(dist, 0x7f, sizeof(dist));for (int i = 0; i < A.size(); ++i) {g[ A[i] ][ B[i] ] = g[ B[i] ][ A[i] ] = D[i];} int d = 10001;for (int i = 0; i < A.size(); ++i) {if (0 == A[i] || 0 == B[i]) {d = min(d, D[i]);}}  if (d > 10000) {return "Impossible";}std::set< pair<long long, pii> > Q;Q.insert(mkp(0, mkp(0, 0)));dist[0][0] = 0;pii cur;while (!Q.empty()) {cur = (*Q.begin()).second;int u = cur.second;int v = cur.first;long long m = (*Q.begin()).first;Q.erase(Q.begin());for (int i = 0; i < N; ++i) {if (g[u][i]) {int w = (v + g[u][i]) % (2 * d);long long temp = m + g[u][i];if (temp < dist[w][i]) {std::set<pair<long long, pii> >::iterator it = Q.find(mkp(dist[w][i], mkp(w, i)));if (it != Q.end()) {Q.erase(it);}dist[w][i] = temp;Q.insert(mkp(dist[w][i], mkp(w, i)));}}}}if (dist[T % (2 * d)][N - 1] <= T) {return "Possible";} else {return "Impossible";}}};/************** Program End ************************/

SRM 615 D1L2: LongLongTripDiv1相关推荐

  1. problem solving automation

    分工一定要明确啊啊啊啊啊 Nero 数据结构  图论   DP   博弈 JayYe  数论   DP   模拟搜索 博弈  wuyiqi 数论  数据结构   图论 字符串 模拟搜索  几何  20 ...

  2. Topcoder SRM 697题解

    Topcoder SRM 697题解 D1L1 分子分母同乘a[i]: \(a_{i}^{b_{i}+1} mod \prod a_i = 0\) 然后我们考虑质因子p,设质因子p在a[i]中出现cn ...

  3. SAP采购订单下传SRM

    http://www.cnblogs.com/rainysblog/p/6640515.html ZPOSRM 采购订单下传SRM *&---------------------------- ...

  4. Dumpzilla工具第615行bug的解决办法

    Dumpzilla工具第615行bug的解决办法 在Dumpzilla使用选项frequency时,会提示SQL语法错误.这是由于其中SQL语句编写错误.需要将615行中: where url lik ...

  5. srm linux字符界面,如何使用srm安全的删除Linux中的文件

    在Linux平台上,有几个可能的工具可以完成此过程,其中一些工具不能用于删除此类信息,而另一些工具只能可靠地在磁性驱动器上工作.因此,如果您的服务器使用ssd,那么您需要确保使用适合该任务的工具.其中 ...

  6. SRM 583 DIV1

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

  7. Topcoder Srm 671 Div2 1000 BearDestroysDiv2

    \(>Topcoder \space Srm \space 671 \space Div2 \space 1000 \space BearDestroysDiv2<\) 题目大意 : 有一 ...

  8. srm#397_div1_500pt 矩阵乘法+快速模幂

    题目地址:srm#397_div1_500 题目描述: Problem Statement   NOTE: This problem statement contains superscripts t ...

  9. 回答一位朋友关于 SAP SRM 行业 转 CRM 行业的咨询

    这位朋友在知乎上,向我发起了咨询,关于 SAP SRM 模块 转 SAP CRM 模块的可能性.首先要明确传统的 SAP CRM 解决方案有哪些,我之前这篇文章介绍过:SAP的这三款CRM解决方案,您 ...

最新文章

  1. Windows下RStudio环境安装
  2. GitHub 上有个沙雕开发者,做了款斗图工具后火了...
  3. Python的StringIO模块和cStringIO模块
  4. 使用虚拟机安装Linux系统常见的错误以及解决方案
  5. 剑指Offer——二叉树的镜像
  6. python 正则表达式 re.search
  7. tcp三次握手和syn 洪水攻击
  8. 数据科学入门与实战:玩转pandas之四
  9. Atitit 组织软资产建设 知识管理 经济学架构体系
  10. C/C++ 高质量编程--内存,二重指针,指针的高级使用解析 3
  11. 涵盖全网动漫、影视、小说的APP集合,手机有了他们,看遍全网
  12. 裸辞后,随便找份工作干着还是等找到满意的为止?
  13. Chapter 3 Raster Images
  14. 经常打电话的人用什么耳机好?通话质量好的蓝牙耳机推荐
  15. SpringBoot整合Mybaits开发报java.lang.IllegalArgumentException: At least one base package must be specifie
  16. 写脚本的作用是什么?做自媒体,什么样的视频一定要写脚本?
  17. 计算机进制小数位之间的转换,计算机进制之间相互转换
  18. 快手与内涵段子最本质的区别
  19. dirty pipe漏洞,解决办法
  20. 百世集团去年第四季度总收入达90.4亿元 净亏损2400万元

热门文章

  1. K11974 最简真分数
  2. Mac下载安装配置maven
  3. Excel同时按照书名号和顿号分列成3列数据的操作
  4. 有没有好用的文档翻译工具推荐?
  5. 开发落网电台windows phone 8应用的计划(3)
  6. sql --Acess
  7. HDD深圳站:全生命周期赋能开发者,华为引领应用生态升级
  8. 傻傻分不清楚?带你了解设备id
  9. 【微信小程序】全局分享和页面分享
  10. 网络通信之传输层协议