SRM 395(1-250pt)
DIV1 250pt
题意:在平面直角坐标系中,只能走到整点,每次有两种移动方法,可以沿平行于坐标轴方向走,也可以沿45度方向走,前者走一步耗时wt,后者走一步耗时st。比如从(x, y)可以走到(x+1, y),(x-1, y),(x, y+1),(x, y-1)四个点,耗时均为wt,也可以走到(x-1, y+1),(x-1, y-1),(x+1, y+1),(x+1, y-1),耗时均为st。给定x, y, wt, st,求从(0, 0)到(x, y)最少耗时多少。
解法:水题,见代码。
tag: greedy
// BEGIN CUT HERE
/* */
// END CUT HERE
#line 7 "StreetWalking.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <sstream>
#include <set>
#include <queue>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <string>
#include <utility>
#include <map>
#include <ctime>
#include <stack> using namespace std; #define clr0(x) memset(x, 0, sizeof(x))
#define clr1(x) memset(x, -1, sizeof(x))
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size())
#define out(x) cout<<#x<<":"<<(x)<<endl
#define tst(a) cout<<#a<<endl
#define CINBEQUICKER std::ios::sync_with_stdio(false) typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long int64; const double eps = 1e-;
const double PI = atan(1.0)*;
const int inf = / ; inline int MyMod( int a , int b ) { return (a%b+b)%b;} class StreetWalking
{
public:
long long minTime(int x, int y, int wt, int st){
if (st >= wt*) return ((int64)x + y) * wt; if (x < y) swap(x, y);
int64 t = (int64)y * st;
int64 dif = x - y;
if (st < wt){
if (dif & ) return t + (dif-) * st + wt;
return t + dif * st;
}
return t + dif * wt;
} // BEGIN CUT HERE
public:
void run_test(int Case) { if ((Case == -) || (Case == )) test_case_0(); if ((Case == -) || (Case == )) test_case_1(); if ((Case == -) || (Case == )) test_case_2(); if ((Case == -) || (Case == )) test_case_3(); if ((Case == -) || (Case == )) test_case_4(); if ((Case == -) || (Case == )) test_case_5(); if ((Case == -) || (Case == )) test_case_6(); }
private:
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
void verify_case(int Case, const long long &Expected, const long long &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
void test_case_0() { int Arg0 = ; int Arg1 = ; int Arg2 = ; int Arg3 = ; long long Arg4 = 18LL; verify_case(, Arg4, minTime(Arg0, Arg1, Arg2, Arg3)); }
void test_case_1() { int Arg0 = ; int Arg1 = ; int Arg2 = ; int Arg3 = ; long long Arg4 = 16LL; verify_case(, Arg4, minTime(Arg0, Arg1, Arg2, Arg3)); }
void test_case_2() { int Arg0 = ; int Arg1 = ; int Arg2 = ; int Arg3 = ; long long Arg4 = 20LL; verify_case(, Arg4, minTime(Arg0, Arg1, Arg2, Arg3)); }
void test_case_3() { int Arg0 = ; int Arg1 = ; int Arg2 = ; int Arg3 = ; long long Arg4 = 247LL; verify_case(, Arg4, minTime(Arg0, Arg1, Arg2, Arg3)); }
void test_case_4() { int Arg0 = ; int Arg1 = ; int Arg2 = ; int Arg3 = ; long long Arg4 = 240LL; verify_case(, Arg4, minTime(Arg0, Arg1, Arg2, Arg3)); }
void test_case_5() { int Arg0 = ; int Arg1 = ; int Arg2 = ; int Arg3 = ; long long Arg4 = 41010000000LL; verify_case(, Arg4, minTime(Arg0, Arg1, Arg2, Arg3)); }
void test_case_6() { int Arg0 = ; int Arg1 = ; int Arg2 = ; int Arg3 = ; long long Arg4 = 3929LL; verify_case(, Arg4, minTime(Arg0, Arg1, Arg2, Arg3)); } // END CUT HERE };
//by plum rain
// BEGIN CUT HERE
int main()
{
//freopen( "a.out" , "w" , stdout );
StreetWalking ___test;
___test.run_test(-);
return ;
}
// END CUT HERE
SRM 395(1-250pt)的更多相关文章
- SRM593(1-250pt,500pt)
SRM 593 DIV1 250pt 题意:有如下图所示的平面,每个六边形有坐标.将其中一些六边形染色,要求有边相邻的两个六边形不能染同一种颜色.给定哪些六边形需要染色,问最少需要多少种颜色. 解法: ...
- SRM475 - SRM479(1-250pt,500pt)
SRM 475 DIV1 300pt 题意:玩游戏.给一个棋盘,它有1×n(1行n列,每列标号分别为0,1,2..n-1)的格子,每个格子里面可以放一个棋子,并且给定一个只含三个字母WBR,长度为n的 ...
- SRM468 - SRM469(1-250pt, 500pt)
SRM 468 DIV1 250pt 题意:给出字典,按照一定要求进行查找. 解法:模拟题,暴力即可. tag:water score: 0.... 这是第一次AC的代码: /* * Author: ...
- SRM470 - SRM474(1-250pt,500pt)(471-500pt为最短路,474-500pt未做)
SRM 470 DIV1 250pt 题意:有n个房间排成一排,相邻两个房间之间有一扇关闭着的门(共n-1扇),每个门上都标有‘A’-‘P’的大写字母.给定一个数n,表示第n个房间.有两个人John和 ...
- SRM 609(1-250pt, 1-500pt)
嗯....还是应该坚持写题解的好习惯啊... DIV1 250pt 这难度是回到srm 300+的250了嘛...略 // BEGIN CUT HERE /* * Author: plum rain ...
- SRM 442(1-250pt, 1-500pt)
DIV1 250pt 题意:将一个数表示成质因子相乘的形式,若乘式所含数字的个数为质数,则称A为underprime.比如12 = 2*2*3,则含3个数字,是underprime.求A, B之间un ...
- 记第一次TopCoder, 练习SRM 583 div2 250
今天第一次做topcoder,没有比赛,所以找的最新一期的SRM练习,做了第一道题. 题目大意是说 给一个数字字符串,任意交换两位,使数字变为最小,不能有前导0. 看到题目以后,先想到的找规律,发现要 ...
- SRM 513 2 1000CutTheNumbers(状态压缩)
SRM 513 2 1000CutTheNumbers Problem Statement Manao has a board filled with digits represented as St ...
- SRM 510 2 250TheAlmostLuckyNumbersDivTwo(数位dp)
SRM 510 2 250TheAlmostLuckyNumbersDivTwo Problem Statement John and Brus believe that the digits 4 a ...
随机推荐
- android 如何解决模块之间的通讯的耦合问题
使用EventBus http://wuyexiong.github.io/blog/2013/04/30/android-fragment/ http://yunfeng.sinaapp.com/? ...
- nodejs开发环境sublime配置
前端时间使用webstorm搭建一个node.js的学习环境,感觉非常强大.不过由于其加载的速度,每次让都让我抓狂.后来我找到了一个sublime.虽说3.0以上是收费的,2.0暂时免费.官方的不对s ...
- PV、UV、IP的区别
网站推广需要一个网站访问统计工具,常用的统计工具有百度统计.51la.量子恒道统计等.网站访问量常用的指标为PV.UV.IP.那么什么是PV.UV和IP,PV.UV.IP的区别是什么? --首先来看看 ...
- Asp.Net 注册 邮箱激活
数据库 表的设计 State为用户状态 0为禁用 1为可用 默认为0,下面有个UserGUID,这个字段将来用于激活账户 首先你要写一个表单,验证码神马的,这个我就不写了..直接写处理的 代码在 ...
- Linux 添加epel源
1.epel-release yum install epel-release 这样有些没办法通过yum 安装 可以这样安装(例如redis)
- 258. Add Digits(C++)
258. Add Digits Given a non-negative integer num, repeatedly add all its digits until the result has ...
- hdu2962 Trucking (最短路+二分查找)
Problem Description A certain local trucking company would like to transport some goods on a cargo t ...
- 【POJ2887】【块状链表】Big String
Description You are given a string and supposed to do some string manipulations. Input The first lin ...
- PowerDesigner 的7种建模文件
1. 概念数据模型 (CDM) 对数据和信息进行建模,利用实体-关系图(E-R图)的形式组织数据,检验数据设计的有效性和合理性. 2. 逻辑数据模型 (LDM) PowerDesigner 15 ...
- Centos7搭建php+mysql环境(整理篇)
终于将mysql+php环境搭建成功,将之前的整理一下,环境:centos7,本机IP:192.168.1.24,数据库用户名及密码都设为root,测试文件路径:/var/www/html 1.取消c ...