【2021杭电多校赛】2021“MINIEYE杯”中国大学生算法设计超级联赛(7)

1003 Fall with Trees(结论)

找规律

得出S=(4*k-10+3*(2)^(2-k))*d*h

#include<iostream>
#include<cstdio>
#include<math.h>
using namespace std;
int main()
{
	int T;
	scanf_s("%d", &T);
	while (T--)
	{
		int k;
		scanf_s("%d", &k);
		int x, y;
		int xl, yl, xr, yr;
		scanf_s("%d%d%d%d%d%d", &x, &y, &xl, &yl, &xr, &yr);
		int h;
		h = y - yl;
		double d;
		d = (xr - xl)*1.0 / 2;
		double sum;
		sum = 4 * k - 10 + 3 * pow(2, 2 - k);
		printf("%.3lf\n", sum * h * d);
	}
}

 1008 Smzzl with Greedy Snake (模拟)

模拟题,设每次初始坐标(x,y),初始方向d,每次食物位置为(tx,ty)

然后分类讨论初始d=0,d=1,d=2,d=3的情况,注意改变头的方向

最后将x=tx,y=ty,d=td(即将上一个食物的位置变为下一个食物的初始位置)

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int T;
	cin >> T;
	while (T--)
	{
		string ans = "";
		int x, y, d;
		cin >> x >> y >> d;
		int n;
		cin >> n;
		while (n--)
		{
			int tx1;
			int ty1;
			int p1;
			int p2;
			int td;
			cin >> tx1 >> ty1;
			int xd = abs(tx1 - x);
			int yd = abs(ty1 - y);
			if (tx1 > x)
				p1 = 1;
			if (tx1 < x)
				p1 = 3;
			if (ty1 > y)
				p2 = 0;
			if (ty1 < y)
				p2 = 2;
			if (d == 0){
				if (p2 == 0){
					for (int i = 1; i <= yd; i++) ans+="f";
					if (p1 == 1) { ans += "c"; td = 1; }
					if (p1 == 3) { ans += "u"; td = 3; }
					for (int i = 1; i <= xd;i++) ans += "f";
				}
				else{
					if (p1 == 1)  ans += "c";
					if (p1 == 3) ans += "u";
					for (int i = 1; i <= xd; i++) ans += "f";
					if (p1 == 1)  ans += "c";
					if (p1 == 3) ans += "u";
					for (int i = 1; i <= yd; i++) ans += "f"; td = 2;
				}
			}
			if (d == 2){
				if (p2 == 2)
				{
					for (int i = 1; i <= yd; i++) ans+="f";
					if (p1 == 1) { ans += "u"; td = 1; }
					if (p1 == 3) { ans += "c"; td = 3; }
					for (int i = 1; i <= xd; i++) ans += "f";
				}
				else
				{
					if (p1 == 1)  ans += "u";
					if (p1 == 3) ans += "c";
					for (int i = 1; i <= xd; i++) ans += "f";
					if (p1 == 1)  ans += "u";
					if (p1 == 3) ans += "c";
					for (int i = 1; i <= yd; i++) ans += "f"; td = 0;
				}
			}
			if (d == 1)
			{
				if (p1 == 1) {
					for (int i = 1; i <= xd; i++) ans += "f";
					if (p2 == 2) { ans += "c"; td = 2; }
					if (p2 == 0) { ans += "u"; td = 0; }
					for (int i = 1; i <= yd; i++) ans += "f";
				}
				else {
					if (p2 == 0) ans += "u";
					if (p2 == 2) ans += "c";
					for (int i = 1; i <= yd; i++) ans += "f";
					if (p2 == 0) ans += "u";
					if (p2 == 2) ans += "c";
					for (int i = 1; i <= xd; i++) ans += "f"; td = 3;
				}
			}
			if (d == 3)
			{
				if (p1 == 3) {
					for (int i = 1; i <= xd; i++) ans += "f";
					if (p2 == 2) { ans += "u"; td = 2; }
					if (p2 == 0) { ans += "c"; td = 0; }
					for (int i = 1; i <= yd; i++) ans += "f";
				}
				else {
					if (p2 == 0) ans += "c";
					if (p2 == 2) ans += "u";
					for (int i = 1; i <= yd; i++) ans += "f";
					if (p2 == 0) ans += "c";
					if (p2 == 2) ans += "u";
					for (int i = 1; i <= xd; i++) ans += "f"; td = 1;
				}
			}
			x = tx1;
			y = ty1;
			d = td;
		}
		cout <<ans<<endl;
	}
}

1007 Link with Limit (图论找环)

题意:使得图中所有环均值相等。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值