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)的更多相关文章

  1. SRM593(1-250pt,500pt)

    SRM 593 DIV1 250pt 题意:有如下图所示的平面,每个六边形有坐标.将其中一些六边形染色,要求有边相邻的两个六边形不能染同一种颜色.给定哪些六边形需要染色,问最少需要多少种颜色. 解法: ...

  2. SRM475 - SRM479(1-250pt,500pt)

    SRM 475 DIV1 300pt 题意:玩游戏.给一个棋盘,它有1×n(1行n列,每列标号分别为0,1,2..n-1)的格子,每个格子里面可以放一个棋子,并且给定一个只含三个字母WBR,长度为n的 ...

  3. SRM468 - SRM469(1-250pt, 500pt)

    SRM 468 DIV1 250pt 题意:给出字典,按照一定要求进行查找. 解法:模拟题,暴力即可. tag:water score: 0.... 这是第一次AC的代码: /* * Author: ...

  4. SRM470 - SRM474(1-250pt,500pt)(471-500pt为最短路,474-500pt未做)

    SRM 470 DIV1 250pt 题意:有n个房间排成一排,相邻两个房间之间有一扇关闭着的门(共n-1扇),每个门上都标有‘A’-‘P’的大写字母.给定一个数n,表示第n个房间.有两个人John和 ...

  5. SRM 609(1-250pt, 1-500pt)

    嗯....还是应该坚持写题解的好习惯啊... DIV1 250pt 这难度是回到srm 300+的250了嘛...略 // BEGIN CUT HERE /* * Author: plum rain ...

  6. SRM 442(1-250pt, 1-500pt)

    DIV1 250pt 题意:将一个数表示成质因子相乘的形式,若乘式所含数字的个数为质数,则称A为underprime.比如12 = 2*2*3,则含3个数字,是underprime.求A, B之间un ...

  7. 记第一次TopCoder, 练习SRM 583 div2 250

    今天第一次做topcoder,没有比赛,所以找的最新一期的SRM练习,做了第一道题. 题目大意是说 给一个数字字符串,任意交换两位,使数字变为最小,不能有前导0. 看到题目以后,先想到的找规律,发现要 ...

  8. SRM 513 2 1000CutTheNumbers(状态压缩)

    SRM 513 2 1000CutTheNumbers Problem Statement Manao has a board filled with digits represented as St ...

  9. SRM 510 2 250TheAlmostLuckyNumbersDivTwo(数位dp)

    SRM 510 2 250TheAlmostLuckyNumbersDivTwo Problem Statement John and Brus believe that the digits 4 a ...

随机推荐

  1. ajax使用中发现的问题与深入扩展(for循环中嵌套ajax)

    在学习ajax的过程中,我曾经遇到过这样的一个问题,为了得到一个详情列表,我要先向服务器去请求得到索引表,简单描述就是ajax中的success中的for循环中再次嵌套了ajax,结果第二层succe ...

  2. java 计算器SWT/RAP(版本3)键盘鼠标兼容

    java 计算器SWT/RAP(版本3)键盘鼠标兼容,之前版本也对,但存在线程失效问题,当多人访问时,就容易线程失效,一直犯得一个错误就是一直用static变量和static方法, 之前加了什么js界 ...

  3. 【HOJ1356】【Miller_rabin素性测试】Prime Judge

    Given a positive integer, your job is writing a program to determine whether it is a prime number or ...

  4. 反射给对象赋值遇到的问题——类型转换[转http://blog.csdn.net/xiaohan2826/article/details/8536074]

    发布时间:2012-10-25 10:49浏览次数:225 给一个对象属性赋值可以通过PropertyInfo.SetValue()方式进行赋值,但要注意值的类型要与属性保持一致.   创建对象实例的 ...

  5. js 强制转换

    强制转换为布尔类型: <script> var text =Boolean(0) //=>以下转换的类型都为false text = Boolean(0.0) text = Bool ...

  6. dedecms 文章内容文章名字和文章网址的调用

    文章标题: <a href="{dede:field name='arcurl'/}">{dede:field.title/}</a> 本文章网址: < ...

  7. 1s延时程序

    #include <reg52.h>sbit P1_0 = P1^0;void Delay(); // 下面引用时一定要和这里的大小写一致否则会有警告或错误 void Main(){whi ...

  8. 七天学会SALTSTACK自动化运维 (2)

    七天学会SALTSTACK自动化运维 (2) 导读 Grains Pillar 总结 参考链接 导读 上一篇主要介绍了安装和基本的使用方法,但是我认为如果理解了相关概念的话,使用会更加顺手,因为毕竟每 ...

  9. android开发学习笔记:圆角的Button

    转自:http://www.cnblogs.com/gzggyy/archive/2013/05/17/3083218.html 在res目录下的drawable-mdpi建立xml文件shape.x ...

  10. codevs 4163 hzwer与逆序对

    传送门 题目描述 Description hzwer在研究逆序对. 对于数列{a},如果有序数对(I,j)满足:i<j,a[i]>a[j],则(i,j)是一对逆序对. 给定一个数列{a}, ...