zoj 3580 angry birds 愤怒的小鸟(zoj 的题目就是与时俱进啊)

本文深入探讨了游戏开发领域的多种技术,包括Unity、Cocos2d-X等游戏引擎,以及人工智能和音视频处理技术的应用,如AR特效、语音识别、图像处理等。同时,文章还涉及了大数据开发、云计算、DevOps等现代技术栈,旨在为开发者提供全面的技术视角。

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

Angry Birds

Time Limit: 4 Seconds      Memory Limit: 65536 KB

In the famous game Angry Birds, players can choose a direction to shoot a blue bird, which can be spilt into three birds to hit those annoying pigs or wood boards. Birds flies in parabola with gravity constant g=9.8m/s2.

This time, Paopao is commanding her birds to break wood boards on the ground following these rules:

  • Birds are shooted in the starting position (0,Y).
  • Birds' initial speed is fixed as V. However, her direction can be arbitrarily determined by Paopao.
  • Each Bird can be spilt into three birds in the starting position. Assuming the angle of the orign direction vector is p, the angles after spilting is p-pi/12p, and p+pi/12(in Radian). Three birds share the same initial speed V. Notice that there is a ceiling with y=Y, that is to say, any birds flying above the starting position will disappear instantly.
  • Wood boards are placed on the ground (the y-axis of ground is 0). The thickness of each board can be ignored and each board can be regarded as a simple line with cordinates (x1,0)-(x2,0). Once hit by a bird, the board will disappear. Hitting on the boundary of the board won't break the board and no boards will overlap each other.

Apparently, some boards can be destroyed in the same time with one shoot. Paopao wants to know the least number of shoots she need to destroy all boards.

Input

The problem contains multiple cases.

Each case starts with one integer and two real numbers indicating the number of boards n (1 ≤ n ≤ 16), the initial speed V (0 < V ≤ 1000), and Y (0 < Y ≤ 1000).

The following n lines each contains two real numbers x1x2 (0 ≤ x1 < x2 ≤ 1000000), describing the cordinates of a board.

Process to the end of file.

Output

For each test case, output the least number of shoots needed to eliminate all boards in a single line. If some board cannot be broken, output -1 instead.

Sample Input

2 1.0 1.0
0 0.0001
0.45 0.45001
3 1.0 1.0
0 0.0001
0.45 0.45001
0.5 0.6

Sample Output

2
-1



稍作预处理然后 bitmask dp



#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

//#undef _DEBUG

#ifdef _DEBUG
#define debug_printf(...) printf(__VA_ARGS__)
#else
#define debug_printf(...)
#endif

int n;
double V;
double Y;

const int MAXN = 16;

struct Bridge
{
    double x0;
    double x1;
};

Bridge bridge[MAXN];
int bridges;

void get()
{
	if (scanf ("%d%lf%lf", &n, &V, &Y) == EOF) {
		exit(0);
	}

	for (int i=0; i<n; ++i) {
		scanf ("%lf%lf", &bridge[i].x0, &bridge[i].x1);
		if (bridge[i].x0 > bridge[i].x1) {
			swap (bridge[i].x0, bridge[i].x1);
		}
	}

	bridges = n;
}

struct Shoot
{
	double angle;
    int hitsBridge;
};

bool isDoubleEqual (double, double);

const double PI = 3.141592653589793;

const double ESP = 1e-7;

const double g = 9.8;

const double SHOOT_ANGLE_OFFSET = ESP / 100;

const int INF = 100000;

bool isDoubleEqual (double x, double y)
{
	return fabs (x - y) < ESP;
}

double flyingTime (double virticalVelocity)
{
	double v = virticalVelocity;
	double ret = (-v + sqrt (v * v + 2.0 * g * Y)) / g;
	return ret;
}

double flyingDistance (double angle)
{
	double ret = V * cos (angle) * flyingTime (V * sin (angle));
	return ret;
}

double angle (double x)
{
	double lo = 0.0;
	double hi = PI / 2.0;

	if (flyingDistance (lo) < x) {
		return PI * 2.0;
	}

	while (fabs (lo - hi) >= ESP / 100) {
		double m = (lo + hi) / 2.0;
		if (flyingDistance (m) < x) {
			hi = m;
		} else {
			lo = m;
		}
	}

	return lo;
}

Shoot shoot[MAXN * 6];
int shoots;

double dAngle[3] = {-PI / 12.0, 0.0, PI / 12.0};

void print_shoots (bool printHitsBridge)
{
	debug_printf ("\n%d shoots:\n", shoots);
	for (int s=0; s<shoots; ++s) {
		debug_printf ("ang: %.6lf", shoot[s].angle);
		if (printHitsBridge) {
            for (int b=0; b<bridges; ++b) {
                if ((1 << b) & shoot[s].hitsBridge) {
                    debug_printf (" %d", b);
                }
            }
		}
		debug_printf ("\n");
	}
}

void makeShoots()
{
	debug_printf ("\n%d bridges:\n", bridges);
	for (int i=0; i<bridges; ++i) {
		debug_printf ("(%.6lf, %.6lf)\n", bridge[i].x0, bridge[i].x1);
	}

	shoots = 0;
	for (int i=0; i<bridges; ++i) {
		for (int a=0; a<3; ++a) {
			shoot[shoots++].angle = angle (bridge[i].x0) + dAngle[a] - SHOOT_ANGLE_OFFSET;
		}

		for (int a=0; a<3; ++a) {
			shoot[shoots++].angle = angle (bridge[i].x1) + dAngle[a] + SHOOT_ANGLE_OFFSET;
		}
	}

    for (int i=0; i<shoots; ++i) {
        shoot[i].hitsBridge = 0;
    }

	for (int s=0; s<shoots; ++s) {
		for (int a=0; a<3; ++a) {

			debug_printf ("s = %d, a = %d\n", s, a);

			double ang = shoot[s].angle + dAngle[a];

			if (ang < 0 || PI / 2.0 < ang) {
				continue;
			}

			double fd = flyingDistance (ang);
			debug_printf ("flyingDistance (%.6lf) == %.6lf\n", ang, fd);

			for (int b=0; b<bridges; ++b) {
				if (bridge[b].x0 <= fd && fd <= bridge[b].x1) {
                    shoot[s].hitsBridge |= (1 << b);
				}
			} // for all bridges

		} // for 3 angles
	} // for all shoots

    // remove unsignificant shoots
	for (int s=0; s<shoots; ++s) {
        if (shoot[s].hitsBridge == 0) {
			debug_printf ("shoot[%d]: angle = %.6lf, hits no bridge\n", s, shoot[s].angle);
			swap (shoot[s], shoot[shoots - 1]);
			--shoots;
			--s;
		}
	}

	print_shoots (true);
}

bool bridgeBroken[MAXN];

int dp[1 << MAXN];

int minShoots (int bridgeMask)
{
    if (dp[bridgeMask] != -1) {
        return dp[bridgeMask];
    }

    if (bridgeMask == 0) {
        return dp[bridgeMask] = 0;
    }

    dp[bridgeMask] = INF;

    for (int s=0; s<shoots; ++s) {
        int nextBridgeMask = bridgeMask & ~shoot[s].hitsBridge;
        if (nextBridgeMask != bridgeMask) {
            int nextMinShoots = minShoots (nextBridgeMask);
            if (nextMinShoots + 1 < dp[bridgeMask]) {
                dp[bridgeMask] = nextMinShoots + 1;
            }
        }
    }

    return dp[bridgeMask];
}

int main (int argc, char **argv)
{
	while (true) {
		get();
		makeShoots();
        memset (dp, -1, sizeof (dp));
        int ans = minShoots ((1 << n) - 1);
        if (ans >= INF) {
            printf ("-1\n");
        } else {
            printf ("%d\n", ans);
        }
	}

	return 0;
}




开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

内容概要:本文围绕基于Matlab实现的面向光储充一体化社区的有序充电策略展开研究,旨在通过构建优化模型协调光伏发电、储能系统与电动汽车充电负荷之间的能量流动关系,解决综合能源系统中的充电调度问题。研究重点在于实现削峰填谷、降低用户用电成本、提升新能源就地消纳能力等多重目标。通过建立合理的数学优化模型,设定目标函数与约束条件,并借助Matlab工具完成求解与仿真分析,系统展示了如何将复杂的实际工程问题转化为可计算的优化问题,进而为社区级能源管理提供科学决策支持。代码实现部分详尽呈现了系统建模流程与算法求解细节,有助于读者深入理解有序充电策略的技术内涵与实现路径。; 适合人群:具备一定电力系统基础知识、优化理论背景及Matlab编程能力的研究生、科研人员及相关领域工程师,特别适用于从事综合能源系统、电动汽车调度、智能电网、微电网运行等方向的研究与开发人员。; 使用场景及目标:①学习光储充一体化系统的协同运行机制与能量管理策略;②掌握基于Matlab的优化建模方法与求解技术;③复现并改进有序充电调度算法,服务于学术论文撰写或实际工程项目开发;④为后续开展微电网优化调度、需求响应、分布式能源协调控制等相关课题奠定技术基础。; 阅读建议:建议结合Matlab代码逐行分析模型构建逻辑,重点关注目标函数的设计思路与各类物理、运行约束的数学表达方式,尝试调整负荷参数、新能源出力曲线或引入不同优化算法以观察策略敏感性,从而深刻把握有序充电策略的核心原理与应用潜力。
内容概要:本文介绍了名为《考虑源网荷储协调的主动配电网优化调度方法研究》的技术文档,重点围绕主动配电网中“源-网-荷-储”多环节的协调优化问题展开,提出了一种基于Matlab代码实现的优化调度模型。该模型综合考虑了分布式电源(如光伏、风电)、电网结构、负荷需求以及储能系统的协同运行,旨在提升配电网的运行效率、经济性和可靠性。文中详细阐述了数学建模过程,涵盖目标函数的设计(如最小化运行成本、降低网络损耗、提高新能源消纳能力)与多重约束条件(如功率平衡、设备容量限制、电压稳定性等)的处理,并通过Matlab平台进行算法求解与仿真验证,充分展示了所提优化调度策略的有效性与实用性。; 适合人群:具备电力系统、自动化或相关专业背景,熟悉Matlab编程,从事新能源、智能电网、优化调度等领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:① 学习和复现先进的主动配电网多主体协调优化调度方法;② 掌握利用Matlab求解复杂电力系统优化问题的建模与编程技巧;③ 为相关课题研究(如微电网调度、综合能源系统)提供技术参考和代码基础。; 阅读建议:建议读者结合文中提供的Matlab代码进行实践,深入理解模型构建的细节和算法实现逻辑,可尝试修改参数或扩展模型以适应不同的研究场景,从而深化对主动配电网优化调度核心技术的掌握。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值