Facebook Hacker Cup 2017 资格赛

本文探讨了游戏开发中的技术挑战,包括使用不同的游戏引擎如Unity、Unreal Engine等进行3D渲染和动画制作的方法,以及如何利用特定工具和技术实现高效的游戏开发流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Progress Pie

(1)问题描述:

Some progress bars fill you with anticipation. Some are finished before you know it and make you wonder why there was a progress bar at all.

Some progress bars progress at a pleasant, steady rate. Some are chaotic, lurching forward and then pausing for long periods. Some seem to slow down as they go, never quite reaching 100%.

Some progress bars are in fact not bars at all, but circles.

On your screen is a progress pie, a sort of progress bar that shows its progress as a sector of a circle. Envision your screen as a square on the plane with its bottom-left corner at (0, 0), and its upper-right corner at (100, 100). Every point on the screen is either white or black. Initially, the progress is 0%, and all points on the screen are white. When the progress percentage, P, is greater than 0%, a sector of angle (P% * 360) degrees is colored black, anchored by the line segment from the center of the square to the center of the top side, and proceeding clockwise.

While you wait for the progress pie to fill in, you find yourself thinking about whether certain points would be white or black at different amounts of progress.

Input

Input begins with an integer T, the number of points you're curious about. For each point, there is a line containing three space-separated integers, P, the amount of progress as a percentage, and X and Y, the coordinates of the point.

Output

For the ith point, print a line containing "Case #i: " followed by the color of the point, either "black" or "white".

Constraints

1 ≤ T ≤ 1,000 
0 ≤ PXY ≤ 100 

Whenever a point (XY) is queried, it's guaranteed that all points within a distance of 10-6 of (XY) are the same color as (XY).

Explanation of Sample

In the first case all of the points are white, so the point at (55, 55) is of course white.

In the second case, (55, 55) is close to the filled-in sector of the circle, but it's still white.

In the third case, the filled-in sector of the circle now covers (55, 55), coloring it black.


(2)要点:水题,判断点是否在扇形内

(3)代码:

#include <stdio.h>
#include <vector>
#include <algorithm>
using std::vector;

#include <math.h>

// (cx,cy)为圆心,r为半径;
static bool IsPointInCircularSector(float cx,float cy,float r,float ux,float uy,float px,float py,float theta)
{
	static const double pi = 3.1415926535897932884626;
	px -= cx,py -= cy;
	float plen = sqrt(px*px + py*py);
	if(plen > r) return false;                // 不在圆内

	ux -= cx,uy -= cy;
	float ulen = sqrt(ux*ux + uy*uy);

	// 标准化向量
	px /= plen,py /= plen;
	ux /= ulen,uy /= ulen;

	float cross = ux*py - uy*px;                // 小于0则是从u顺时针;大于0是从u逆时针
	//
	//acos(D dot U) < theta
	if(cross < 0) return acos(px*ux + py*uy) < theta;
	else return 2*pi - acos(px*ux + py*uy) < theta;
}

int main()
{
	static const double pi = 3.1415926535897932884626;
	unsigned int nCases = 0;scanf("%d",&nCases);
	for(unsigned int iCases = 1;iCases <= nCases;++iCases)
	{
		unsigned int p = 0;scanf("%d",&p);
		float x = 0,y = 0;scanf("%f%f",&x,&y);
		bool ans = IsPointInCircularSector(50,50,50,50,100,x,y,p/100.0*2*pi);
		printf("Case #%u: %s\n",iCases,ans?"black":"white");
	}
	return 0;
}


Lazy Loading

(1)问题描述:

Wilson works for a moving company. His primary duty is to load household items into a moving truck. Wilson has a bag that he uses to move these items. He puts a bunch of items in the bag, moves them to the truck, and then drops the items off.

Wilson has a bit of a reputation as a lazy worker. Julie is Wilson's supervisor, and she's keen to make sure that he doesn't slack off. She wants Wilson to carry at least 50 pounds of items in his bag every time he goes to the truck.

Luckily for Wilson, his bag is opaque. When he carries a bagful of items, Julie can tell how many items are in the bag (based on the height of the stack in the bag), and she can tell the weight of the top item. She can't, however, tell how much the other items in the bag weigh. She assumes that every item in the bag weighs at least as much as this top item, because surely Wilson, as lazy as he is, would at least not be so dense as to put heavier items on top of lighter ones. Alas, Julie is woefully ignorant of the extent of Wilson's lack of dedication to his duty, and this assumption is frequently incorrect.

Today there are N items to be moved, and Wilson, paid by the hour as he is, wants to maximize the number of trips he makes to move all of them to the truck. What is the maximum number of trips Wilson can make without getting berated by Julie?

Note that Julie is not aware of what items are to be moved today, and she is not keeping track of what Wilson has already moved when she examines each bag of items. She simply assumes that each bagful contains a total weight of at least k * w where k is the number of items in the bag, and w is the weight of the top item.

Input

Input begins with an integer T, the number of days Wilson "works" at his job. For each day, there is first a line containing the integer N. Then there are N lines, the ith of which contains a single integer, the weight of the ith item, Wi.

Output

For the ith day, print a line containing "Case #i: " followed by the maximum number of trips Wilson can take that day.

Constraints

1 ≤ T ≤ 500 
1 ≤ N ≤ 100 
1 ≤ Wi ≤ 100 

On every day, it is guaranteed that the total weight of all of the items is at least 50 pounds.

Explanation of Sample

In the first case, Wilson can make two trips by stacking a 30-pound item on top of a 1-pound item, making the bag appear to contain 60 pounds.

In the second case, Wilson needs to put all the items in the bag at once and can only make one trip.

In the third case, one possible solution is to put the items with odd weight in the bag for the first trip, and then the items with even weight in the bag for the second trip, making sure to put the heaviest item on top.

(2)要点:贪心算法,注意这些测试用例:49/50/51/50 1/51 1/49 1/25 24 24 24/25 25 25 25,第一个样例答案是0,最后样例答案是2,其他答案都是1

(3)代码:

#include <stdio.h>
#include <vector>
#include <algorithm>
using std::vector;

int main()
{
	static const unsigned int limit = 50;
	unsigned int nCases = 0;scanf("%d",&nCases);
	for(unsigned int iCases = 1;iCases <= nCases;++iCases)
	{
		unsigned int n = 0;scanf("%d",&n);
		vector<unsigned int> data(n,0);
		for(unsigned int i = 0;i < n;++i) scanf("%d",&data[i]);
		std::sort(data.begin(),data.end());
		unsigned int ans = 0;
		for(unsigned int i = n - 1,j = 0;j <= i && j < n && i != (unsigned int)(-1);--i)
		{
			unsigned int count = (limit+data[i]-1)/data[i];
			if(j + count - 1 > i) continue;
			j += (count - 1);
			++ ans;
		}
		printf("Case #%u: %u\n",iCases,ans);
	}
	return 0;
}



Fighting the Zombie

(1)问题描述:

"Okay, Wizard, cast your spell!"

But which of your many spells to cast? In the ever-popular role-playing game Dungeons & Dragons, or D&D, you determine a spell's damage by rolling polyhedral dice with 4, 6, 8, 10, 12, or 20 sides. Since there's a lot of dice-rolling involved, players use shorthand to denote which dice should be rolled. XdY means "roll a Y-sided die X times, and sum the rolls''. Sometimes, you must add or subtract a value Z after you finish rolling, in which case the notation is XdY+Z or XdY-Z respectively.

For example, if you roll 2d4+1, you'll end up with a result between 3 and 9 inclusive. If you roll 1d6-3, your result will be between -2 and 3 inclusive.

In D&D, wizards are powerful but flimsy spellcasters. As a wizard fighting a zombie, your best strategy is to maximize the chance that you can kill the zombie with a single spell before it has a chance to retaliate. What spell should you cast?

Input

Input begins with an integer T, the number of zombies you'll fight. For each zombie, there are two lines. The first contains two integers, H and S, the minimum amount of damage it takes to defeat the zombie, and the number of spells you have prepared, respectively. The second line contains S spell descriptions separated by single spaces. A spell description is simply the amount of damage a spell does in the notation described above.

Output

For each zombie, print a line containing the probability of defeating the zombie if you select your spell optimally.

Absolute and relative errors of up to 1e-6 will be ignored.

Constraints

1 ≤ T ≤ 1,000 
1 ≤ H ≤ 10,000 
2 ≤ S ≤ 10 

Additionally, the following constraints will hold for each spell:

1 ≤ X ≤ 20 
Y ∈ {4, 6, 8, 10, 12, 20} 
1 ≤ Z ≤ 10,000, if Z is specified. 
XY, and Z will be integers with no leading zeros. 

Explanation of Sample

In the first case, you can guarantee a kill with the first spell, which must always do at least 2 damage.

In the third case, your first spell is the best. If you roll a 4, you'll do the requisite 8 damage. The second spell requires rolling a 4 on two dice rather than just one, and the third spell requires rolling a 4 on all three dice.


(2)要点:预计算各种骰子的投掷1-20次的各种值概率

(3)代码:

#include <stdio.h>
#include <vector>
#include <algorithm>
using std::vector;

void calc_die_prob(unsigned int die,vector< vector<long double> >& probs)
{
	static const unsigned int maxcount = 20;
	unsigned int maxsum = maxcount*die;
	probs.resize(maxcount+1,vector<long double>(maxsum+1,0));
	probs[0][0] = 1;
	for(unsigned int i = 1;i <= maxcount;++i)				// 20
	{
		for(unsigned int k = 1;k <= die;++k)
		{
			for(unsigned int j = 0;j + k <= maxsum;++j)
			{
				probs[i][j+k] += probs[i-1][j]/die;
			}
		}
	}
}

int main()
{
	vector< vector<long double> > probs[21];
	calc_die_prob(4,probs[4]);
	calc_die_prob(6,probs[6]);
	calc_die_prob(8,probs[8]);
	calc_die_prob(10,probs[10]);
	calc_die_prob(12,probs[12]);
	calc_die_prob(20,probs[20]);

	static const size_t buff_size = 1000;
	static const size_t maxsize = 10*20*20;        // 4000
	char buff[buff_size] = { 0 };
	unsigned int nCases = 0;scanf("%d",&nCases);

	for(unsigned int iCases = 1;iCases <= nCases;++iCases)
	{
		unsigned int h = 0,s = 0,x = 0,y = 0;
		scanf("%d%d",&h,&s);

		long double ans = 0;
		for(unsigned int i = 0;i < s;++i)					// 10
		{
			scanf("%s",buff);
			int delta = 0,z = 0;
			if(NULL != strchr(buff,'+'))
			{
				sscanf(buff,"%dd%d+%d",&x,&y,&z);
				delta += z;
			}
			else if(NULL != strchr(buff,'-'))
			{
				sscanf(buff,"%dd%d-%d",&x,&y,&z);
				delta -= z;
			}
			else
			{
				sscanf(buff,"%dd%d",&x,&y);
			}

			long double prob = 0;
			if(delta > (int)h) delta = (int)(h - 1);
			for(unsigned int i = h - delta;i <= x*y;++i) prob += probs[y][x][i];
			if(prob > ans) ans = prob;
		}

		printf("Case #%u: %.9f\n",iCases,(double)(ans));
	}
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值