您的位置:首页 > 其它

Codeforces Round #281 (Div. 2) C. Vasya and Basketball&D. Vasya and Chess

2015-01-23 18:09 501 查看
C. Vasya and Basketbal

题意:篮球比赛中a队(n个)和b队(m个)的每次投球距离已经记录下来;求一个三分线,使a-b最大的比分a:b;(若有多组输出a最大的)。

题解:简简单枚举吧,注意的是压线是取2分的;把数据记录下排序(为的用二分查找),依次枚举;

这里要感谢STL的 upper_bound()函数。

#define INF 0x7fffffff
#define eps (1e-9)
#define mid 250
#define maxn 1000000000
#define clearto(s,x) memset(s,x,sizeof(s))
using namespace std;

int n, m, tot=0;
int dat1[200005];
int dat2[200005];

int main()
{
//freopen("E:\DATA.txt","r",stdin);
//int TT=1,tt+=1;            scanf("%d",&TT);
int i=0,j=0,t=0;
scanf("%d",&n);
for(i=0;i<n;i++) {    scanf("%d",dat1+i);    }
scanf("%d",&m);
for(i=0;i<m;i++) {    scanf("%d",dat2+i);    }
sort(dat1,dat1+n);    sort(dat2,dat2+m);
int val1,val2;
int a,b;
if(n-m>=0)  {  a=3*n;     b=3*m;  }    // 三分线为零时
else        {  a=2*n;     b=2*m;  }    // 三分线无穷的时
for(i=0;i<n;i++)
{                                      // 注意有相同距离
val1=upper_bound(dat1,dat1+n,dat1[i])-dat1;
val1=val1*2+(n-val1)*3;
val2=upper_bound(dat2,dat2+m,dat1[i])-dat2;
val2=val2*2+(m-val2)*3;
if((val1-val2)==(a-b))
{   if(val1>a)    {  a=val1;    b=val2;  }          }
else if((val1-val2)>(a-b))
{   a=val1;    b=val2;  }
}
for(i=0;i<m;i++)
{                                      // upper_bound()返回第一个大于val的位置
val2=upper_bound(dat2,dat2+m,dat2[i])-dat2;
val2=val2*2+(m-val2)*3;
val1=upper_bound(dat1,dat1+n,dat2[i])-dat1;
val1=val1*2+(n-val1)*3;
if((val1-val2)==(a-b))
{   if(val1>a)    {  a=val1;    b=val2;  }          }
else if((val1-val2)>(a-b))
{   a=val1;    b=val2;  }
}
printf("%d:%d",a,b);
return 0;
}


D. Vasya and Chess

题意:不解释;

网上看到了几个参考:

1(原地址).

思路:判断奇偶,偶数白赢,第一步走1 2;奇数黑赢。

白的最优决策,就是自己行动后保持和黑皇后横坐标的差为偶数,第一步往右,然后黑上下自己也上下,黑左右自己也左右,黑斜走自己也斜走。

2(原地址).

如果n是奇数,黑子赢。如果n是偶数,白子赢,输出的第一步是(1,2)

我的想法是对于最中间那道竖线对称,白子怎么走黑子也怎么走

比如对于5*5的棋盘,从中间第三道划分成左边2*5的部分和右边2*5的部分

那么白子在左边走,黑子在右边走。白子怎么走黑子也怎么走

当白子走完所有左边可以走的路的时候,它一定要从第二道走到中间第三道来

但是此时黑子一定在第四道跟白子在同一水平线的位置

所以白子能到达的第三道的点黑子也一定能到达

因此n是奇数时白子必败,同理n是偶数时黑子必败。

-------------------

白的只要一直右走

每走一次,黑的活动范围就会少条一条对角线

黑的可以学它往左走,显然如果n是奇数白子就输了

否则的话无论黑怎么走都是输
原题描述:

D. Vasya and Chess

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess.

The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is located on the same vertical, horizontal or diagonal line with queen, and the cell contains a piece of the enemy color, the queen is able to move
to this square. After that the enemy's piece is removed from the board. The queen cannot move to a cell containing an enemy piece if there is some other piece between it and the queen.

There is an n × n chessboard. We'll denote a cell on the intersection of the r-th
row and c-th column as (r, c). The
square (1, 1)contains the white queen and the square (1, n) contains
the black queen. All other squares contain green pawns that don't belong to anyone.

The players move in turns. The player that moves first plays for the white queen, his opponent plays for the black queen.

On each move the player has to capture some piece with his queen (that is, move to a square that contains either a green pawn or the enemy queen). The player loses if either he cannot capture any piece during his move or the opponent took his queen during the
previous move.

Help Vasya determine who wins if both players play with an optimal strategy on the board n × n.

Input

The input contains a single number n (2 ≤ n ≤ 109)
— the size of the board.

Output

On the first line print the answer to problem — string "white" or string "black",
depending on who wins if the both players play optimally.

If the answer is "white", then you should also print two integers r and c representing
the cell (r, c), where the first player should make his first move to win. If there are multiple such cells, print the one with the minimum r.
If there are still multiple squares, print the one with the minimum c.

Sample test(s)

input
2


output
white
1 2


input
3


output
black


Note

In the first sample test the white queen can capture the black queen at the first move, so the white player wins.

In the second test from the statement if the white queen captures the green pawn located on the central vertical line, then it will be captured by the black queen during the next move. So the only move for the white player is to capture the green pawn located
at(2, 1).

Similarly, the black queen doesn't have any other options but to capture the green pawn located at (2, 3), otherwise if it goes to the middle vertical line, it
will be captured by the white queen.

During the next move the same thing happens — neither the white, nor the black queen has other options rather than to capture green pawns situated above them. Thus, the white queen ends up on square (3, 1),
and the black queen ends up on square (3, 3).

In this situation the white queen has to capture any of the green pawns located on the middle vertical line, after that it will be captured by the black queen. Thus, the player who plays for the black queen wins.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: