TopCoder SRM 598 Div1 第2题

原创 2013年12月02日 21:15:29

Problem Statement

 

Fox Ciel is playing a board game with her friend Squirrel Liss. The game is played on an infinite strip of paper. The strip of paper is divided into consecutive cells. Each cell has an integer coordinate. Formally, for each integer i, the left neighbor of cell i is cell (i-1) and the right neighbor of cell i is cell (i+1).


Each of the players has a single token called the fencer. At the beginning of the game, Ciel's fencer is in cell 0 and Liss's fencer is in cell d. Each of the fencers has two limits: its maximum move length and its hitting range. For Ciel's fencer the maximum move length is mov1 and the hitting range is rng1. Similarly, for Liss's fencer we have the parameters mov2 and rng2. Note that the parameters of Liss's fencer may differ from the ones of Ciel's fencer.


The players take alternating turns. Ciel goes first. In each turn the current player starts by moving her fencer. The distance between the original cell and the destination cell must be at most equal to the fencer's maximum move length. (It is also allowed to leave the fencer in the same cell.) Then, the current player checks whether the other fencer lies within the hitting range - that is, whether the current distance between the fencers is at most equal to the current fencer's hitting range. If that is the case, the game ends and the current player wins.


You are given the ints mov1, mov2, rng1, rng2, and d. Return "Ciel" (quotes for clarity) if Fox Ciel has a winning strategy, "Liss" if Squirrel Liss has a winning strategy, and "Draw" otherwise.

Definition

 

Class:

FoxAndFencing

Method:

WhoCanWin

Parameters:

int, int, int, int, int

Returns:

string

Method signature:

string WhoCanWin(int mov1, int mov2, int rng1, int rng2, int d)

(be sure your method is public)

 

 

Constraints

-

mov1 will be between 1 and 100,000,000, inclusive.

-

mov2 will be between 1 and 100,000,000, inclusive.

-

rng1 will be between 1 and 100,000,000, inclusive.

-

rng2 will be between 1 and 100,000,000, inclusive.

-

d will be between 1 and 100,000,000, inclusive.

Examples

0)

 

 

1

58

1

58

2

Returns: "Ciel"

The attributes of Ciel's fencer are much smaller than the attributes of Liss's fencer. Luckily for Ciel, she can win the game in her first turn: she should move her fencer to cell 1 and from there she can hit the other fencer.

1)

 

 

2

1

1

100

50

Returns: "Liss"

Ciel cannot score a hit in the first turn. After Ciel's turn, her fencer will be on one of the cells {-2,-1,0,1,2}. Regardless of its precise location, Liss can always move her fencer one cell to the left and then hit Ciel.

2)

 

 

2

1

1

100

150

Returns: "Draw"

Clearly, Ciel has no chance of winning this game. However, this time the initial distance d is big enough for Ciel to escape.

3)

 

 

100

100

100

100

100000000

Returns: "Draw"

 

4)

 

 

100

1

100

1

100000000

Returns: "Ciel"

 

5)

 

 

100

1

100

250

100000000

Returns: "Draw"

 

6)

 

 

100

1

100

150

100000000

Returns: "Ciel"

 

7)

 

 

100

50

100

1

100000000

Returns: "Ciel"

 

8)

 

 

100

150

100

1

100000000

Returns: "Draw"

 

类型:博弈  难度:2

题意:不知道为啥这道不算太难的博弈会是550分的题,考察细节吧。Ciel和Liss在一条直线的两点,相距距离为d,他们每次能走的最大距离为mov1,mov2,他们的武器能够到的范围为rng1,rng2,Ciel先走,每一步包括走一段并可以尝试用武器打对方,每个人都用最优策略走,问谁会赢,还是平局

分析:1、首先应该考虑第一回合会不会分出胜负,若mov1+rng1>=d,那么Ciel赢,若mov2+rng2>=d+mov1,Liss赢(Liss后手,要加mov1)

2、若第一回合分不出胜负,那么需要比较mov1,mov2(之前考虑比较mov1+rng1和mov2+rng2,发现并不正确,每次只能走mov步,所以要按mov来分情况)

(1)mov1==mov2,一定是平局

(2)mov1>mov2,Ciel走得快,那么Ciel如果想赢,必须在追着Liss走了x步时能打到Liss,但是又要防止Liss在x-1步时反向走倒打一耙,所以需要满足条件,

mov1-mov2+rng1>mov2+rng2。也可以理解为,当Ciel走到和Liss距离为mov1+rng1时,Liss又会走mov2,那么Ciel必须保证第x步走到和Liss距离为mov1-mov2+rng1,然后Liss走第x步走过mov2,然后这时轮到Ciel走第x+1步,此时距离为mov1+rng1,那么一走一打刚好打到Liss,其中,当Ciel走完第x步而Liss未走第x步时,二者距离最近,为mov1-mov2+rng1,必须保证这个距离大于mov2+rng2,否则Liss就会倒打一耙,就是平局。

(3)mov1<mov2,和(2)同理

代码:

#include<string>
#include<cstdio>
#include<vector>
#include<cstring>
#include<map>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;

class FoxAndFencing
{ 	 
	public:
		string WhoCanWin(int mov1, int mov2, int rng1, int rng2, int d)
		{
			if(mov1+rng1>=d) return "Ciel";
			else if(mov2+rng2>=mov1+d) return "Liss";
			
			if(mov1>mov2)
			{
				if((mov1-mov2)+rng1 > mov2+rng2) return "Ciel";
				return "Draw";
			}
			if(mov1<mov2)
			{
				if((mov2-mov1)+rng2 > mov1+rng1) return "Liss";
				return "Draw";
			}
			return "Draw";
		}
};

int main()
{
	FoxAndFencing t;
	cout << t.WhoCanWin(2,1,1,100,50)<<endl;
}





 

[转]Topcoder好题推荐 by 白衣少年

白衣少年        简介:       白衣少年,本科毕业只花了三年同时惊人一跳考入中国科学院软件所。现为微软中国STC员工。他的常用id为白衣少年、白衣少年2012、kyo_key。      ...
  • yew1eb
  • yew1eb
  • 2013年04月06日 00:19
  • 3776

topcoder 刷题笔录 初级篇(一)

摘要:本系列文章为在topcoder上的刷题记录和心得,计划刷题500道。其中,初级题目30道,撰文三篇;中级题目60道,撰文六篇;其他高级题目100道,撰文10篇。 1.题目1——SRM146 ...
  • trochiluses
  • trochiluses
  • 2013年12月20日 16:00
  • 2540

如何在topcoder上进行算法比赛

原文地址:如何在topcoder上进行算法比赛作者:【如来】 topcoder的竞赛页面地址:http://www.topcoder.com/tc   topcoder竞赛有算法,软件设...
  • Stephan14
  • Stephan14
  • 2015年04月12日 11:09
  • 2086

TopCoder SRM 598 Div1 第1题

Problem Statement   Fox Ciel has some items. The weight of the i-th (0-based) item is...
  • maverick1990
  • maverick1990
  • 2013年12月02日 20:20
  • 787

TopCoder SRM 609 Div1 第2题

Problem Statement   We have balls of K different colors. The colors are numbered 0 through ...
  • maverick1990
  • maverick1990
  • 2014年02月16日 15:26
  • 628

TopCoder SRM 602 Div1 第1题

Problem Statement   TypoCoder is a programming contest like TopCoder. TypoCoder also ...
  • maverick1990
  • maverick1990
  • 2013年12月30日 20:48
  • 903

topcoder算法题SRM144 DIV1 500分题

Problem Statement   In most states, gamblers can choose from a wide variety of different ...
  • seigeweapon
  • seigeweapon
  • 2012年02月06日 02:53
  • 285

TopCoder SRM 597 Div1 第1题

Problem Statement   Little Elephant from the Zoo of Lviv likes strings. You are given a str...
  • maverick1990
  • maverick1990
  • 2013年11月25日 23:33
  • 807

topcoder SRM500 DIV1 LEVEL1 250分题

Problem Statement   N friends (numbered from 0 to N-1) play a game called Mafia. The exact ...
  • ascii991
  • ascii991
  • 2012年05月14日 17:08
  • 473

【topcoder】SRM696 div1 550 Clicounting【折半枚举求最大团+高维前缀最大值】

题目链接:【topcoder】SRM696 div1 550 Clicounting最大团可以n2nn2^n搞,然后对这个可以做高维前缀最大值。就可以得到以某个状态的子集构成的最大团的大小。然后显而易...
  • u013368721
  • u013368721
  • 2016年11月07日 22:27
  • 494
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:TopCoder SRM 598 Div1 第2题
举报原因:
原因补充:

(最多只允许输入30个字)