摘要: Link:http://codeforces.com/contest/302/problem/D题意:一个图, 从p1到p2, 需要花费 d·(|xi - xj| + |yi - yj) 时间, 每到一个点将获得时间奖励,求起点到终点的所需具备的最少时间。解:存在负边的最短路, 思路暂时想到FLYOD, 将一条边的花费减去该点的奖励作为本边的权值。#include <iostream>#include <fstream>#include <string>#include <map>#include <cstring>#inc 阅读全文
posted @ 2013-05-07 19:19 Shamaoer 阅读(238) 评论(2) 推荐(0)
摘要: Link:http://codeforces.com/contest/302/problem/CC - Yaroslav and Sequence大意:对一串数列 n + n - 1个数操作, 可对其中n个数字的取反, 操作可重复, 求若干操作后该数列最大和。分析: 简单数学f为数列中负数的个数gao(f)if (f % 2 == 0) 可对数列进行取反使数列全部为正数else if n % 2 == 0 f 为奇数, n - f 为奇数, 必定会存在一个负数 else n - f 为偶数 , gao(n-f)#include <iostream>#include <fst. 阅读全文
posted @ 2013-05-06 20:37 Shamaoer 阅读(243) 评论(0) 推荐(0)
摘要: LINK:http://leetcode.com/onlinejudge#question_78题意:给出一个数组, 求其子集。class Solution {public: vector<vector<int> > ans; void dfs(vector<int> &S, int now, vector<int> t){ if(now >= S.size()){ sort(t.begin(),t.end()); ans.push_back(t); return; } df... 阅读全文
posted @ 2013-04-23 21:22 Shamaoer 阅读(123) 评论(0) 推荐(0)
摘要: LINK:http://leetcode.com/onlinejudge#question_129大意:题目给出一颗二叉树,要求你求出从根到叶子的一条路径上所有数字构成数的和 1 / \ 2 312 + 13 = 25/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */二叉树遍... 阅读全文
posted @ 2013-04-23 20:10 Shamaoer 阅读(193) 评论(0) 推荐(0)
摘要: LINK:http://leetcode.com/onlinejudge#question_130大意:给出一个棋盘, 两种棋子X O, 当O完全被X包围时, 将O修改为X.如:XXO XXOXOX -> XXXXXX XXX解:简单的DFS从边界扫描不被X包含的O。CODE 1 class Solution { 2 public: 3 int r; 4 void dfs(int x, int y, vector<vector<char> > &m){ 5 if(x < 0 || x >= r || y < 0 || y >= r 阅读全文
posted @ 2013-04-23 19:43 Shamaoer 阅读(140) 评论(0) 推荐(0)