首页 > ACM题库 > HDU-杭电 > hdu 2258 Continuous Same Game (1)[解题报告]C++
2014
01-04

hdu 2258 Continuous Same Game (1)[解题报告]C++

Continuous Same Game (1)

问题描述 :

Continuous Same Game is a simple game played on a grid of colored blocks. Groups of two or more connected (orthogonally, not diagonally) blocks that are the same color may be removed from the board. When a group of blocks is removed, the blocks above those removed ones fall down into the empty space. When an entire column of blocks is removed, all the columns to the right of that column shift to the left to fill the empty columns. Points are scored whenever a group of blocks is removed. The number of points per block increases as the group becomes bigger. When N blocks are removed, N*(N-1) points are scored.

LL was interested in this game at one time, but he found it is so difficult to find the optimal scheme. So he always play the game with a greedy strategy: choose the largest group to remove and if there are more than one largest group with equal number of blocks, choose the one which contains the most preceding block ( (x1,y1) is in front of (x2,y2) if and only if (x1<x2 || x1==x2 && y1<y2) ). Now, he want to know how many points he will get. Can you help him?

输入:

Each test case begins with two integers n,m ( 5<=n,m<=20 ), which is the size of the board. Then n lines follow, each contains m characters, indicating the color of the block. There are 5 colors, and each with equal probability.

输出:

Each test case begins with two integers n,m ( 5<=n,m<=20 ), which is the size of the board. Then n lines follow, each contains m characters, indicating the color of the block. There are 5 colors, and each with equal probability.

样例输入:

5 5
35552
31154
33222
21134
12314

样例输出:

32

Hint
35552 00552 00002 00002 00000 00000 31154 05154 05104 00004 00002 00000 33222 01222 01222 00122 00104 00100 21134 21134 21134 25234 25234 25230 12314 12314 12314 12314 12314 12312 The total point is 12+6+6+2+6=32.

http://acm.hit.edu.cn/hoj/problem/view?id=2258

正n边形外接圆半径R=1

沿贴地的那一边滚动m次

求最开始在最左下那个顶点的移动轨迹长度

 

正n边形内角A=2*pi/n

易知该正n边形滚动n次之后回到初始状态

以正五边形为例

五边形如上图滚动4次

 

每次滚动半径如左图

可以计算出一个滚动周期内的顶点走过的距离

其余见代码

#include <stdio.h>
#include <math.h>

const double pi = acos(-1);

int main()
{
    int t, n, m, i, c;
    double angle, r, arclength[1024], circle, totalength;

    scanf("%d",&t);
    while (t--)
    {
        scanf("%d %d", &n, &m);

        angle = 2*pi/n;
        c = m / n;
        m = m % n;
        totalength = 0, circle = 0;

        for (i = 1; i <= n / 2; i++)
        {
            r = sqrt(2 - 2 * cos(i*angle) );
            arclength[i] = arclength[n-i] = angle * r;
        }
        arclength[n] = 0;
        
        for (i = 1; i <= n; i++)
            circle += arclength[i];
        for (i = 1; i <= m; i++)
            totalength += arclength[i];

        totalength += c*circle;
        printf("%.2lf\n", totalength);
    }

    return 0;
}

 

解题转自:http://blog.csdn.net/epk_lee/article/details/8209381


  1. 思路二可以用一个长度为k的队列来实现,入队后判断下队尾元素的next指针是否为空,若为空,则出队指针即为所求。

  2. 问题3是不是应该为1/4 .因为截取的三段,无论是否能组成三角形, x, y-x ,1-y,都应大于0,所以 x<y,基础应该是一个大三角形。小三角是大三角的 1/4.