牛客集训营5补题

 

题目链接:

题号

标题

已通过代码

A

炫酷双截棍

点击查看

B

炫酷五子棋

点击查看

C

炫酷迷宫

点击查看

D

炫酷路途

点击查看

E

炫酷划线

点击查看

F

炫酷回文

点击查看

G

炫酷数字

点击查看

H

炫酷雪花

点击查看

I

炫酷镜子

点击查看

J

炫酷数学

点击查看

 

 

 

A:使用double高精度,坐标系内两点之间距离 sqrt(pow(x1-x2),pow(y1-y2))

判断目标点和 l1+l2 的关系,大的话,结果就是 sqrt(x*x + y*y) - l1 - l2

判断目标点和 l1-l2 的关系,小的话,结果就是 abs(l1 - l2) - sqrt(x*x + y*y)

目标点在范围内就输出0.00000000

 

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    double l1, l2,  x, y,len;
    scanf("%lf%lf%d", &l1, &l2, &t);
    getchar();
    while (t--)
    {
        cin >> x >> y;
        if (sqrt(x*x + y*y) > l1 + l2)
        {
            printf("%.8f\n",sqrt(x*x + y*y) - l1 - l2 );
        }
        else if (sqrt(x*x + y*y) < abs(l1 - l2))
        {
            printf("%.8f\n", abs(l1 - l2) - sqrt(x*x + y*y));
        }
        else printf("0.00000000\n");
    }
    return 0;
}

 

G:注释都写在代码里了 直接看代码

#include<iostream>
using namespace std;
int yin[1000005];//yin[i]代表的是i的因子个数  
int ans[1000005];//ans[i]代表含有i个因子个数的值
void shai()
{
	for (int i = 1; i < 1000004; i++) //i代表因子个数
	{
		for (int j = i; j < 1000004; j += i) //j是i倍数 不断给1~1000000添加每个数的因子
		{
			yin[j]++;//是i的倍数的数  因子个数都加1
		}
		if (ans[yin[i]])//如果ans[i]不为零了,那么说明这个数不是因子个数为i的情况下的最小值,就跳过
			continue;
		else//如果这个数之前没有被赋值 说明是最小的
			ans[yin[i]] = i;

	}
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);//输入很多的时候 关闭流同步
	shai();
	int t, n;
	cin >> t;
	while (t--)
	{
		cin >> n;
		if (ans[n])
			cout << ans[n] << "\n";
		else
			cout << -1 << "\n";
	}
	return 0;
}

 

I:写的比较乱,刚开始想简单了,这算是我第一次写dfs了,纪念一下,第一次只写了向下,然后测试样例发现不对,又想到了还需要判断光线方向,就在dfs里加一个变量h代表方向

#include<bits/stdc++.h>
using namespace std;
int n, m,flag;
char a[510][510];
void dfs(int x,int y,int k,int h)
//x,y代表坐标 ,k代表是否出界,h代表方向 
//上下左右 1234
{
    if (k==0)
    {
        return;
    }
    if ((y>m)||y == 0||x==0) {
        cout << -1 << "\n";
        k = 0;
        return;
    }
    if (x > n) {
        cout << y << "\n";
        return;
    }
    else {
         if (a[x][y] == '.'&&h == 2)    //下
            dfs(x + 1, y, 1, 2);
        else if (a[x][y] == '/'&&h == 2)
            dfs(x, y - 1, 1, 3);
        else if ((a[x][y] == 92) && h == 2)
            dfs(x, y + 1, 1, 4);
        else if (a[x][y] == '.'&&h == 1)    //上
            dfs(x - 1, y, 1, 1);
        else if (a[x][y] == '/'&&h == 1)
            dfs(x, y + 1, 1, 4);
        else if (a[x][y] == 92 && h == 1)
            dfs(x, y - 1, 1, 3);
        else if (a[x][y] == '.'&&h == 3)    //左
            dfs(x, y - 1, 1, 3);
        else if (a[x][y] == '/'&&h == 3)
            dfs(x + 1, y, 1, 2);
        else if (a[x][y] == 92 && h == 3)
            dfs(x - 1, y, 1, 1);
        else if (a[x][y] == '.'&&h == 4)    //右
            dfs(x, y + 1, 1, 4);
        else if (a[x][y] == '/'&&h == 4)
            dfs(x - 1, y, 1, 1);
        else if (a[x][y] == 92 && h == 4)
            dfs(x + 1, y, 1, 2);
    }
}
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++)
            cin >> a[i][j];
    }
    for (int i = 1; i <=m; i++)
    {
        dfs(1,i,1,2);
    }
    return 0;
}

 

J:刚开始想复杂了,又是求排列,又是求组合,做了一个半小时,头都炸了,后来放弃了,做完i题又回来看了看,发现ac的人六百多,肯定没我想的那么复杂啊,又回头看了看,其实就是3^m,快速幂模版套上,a了。

#include<bits/stdc++.h>
using namespace std;
#define mod 998244353
#define ll long long
ll qmi(ll a, ll b, ll p)
{
    ll res = 1;
    while (b)
    {
        if (b & 1) res = (res * a) % p;
        a = (a * a) % p;
        b = b >> 1;
    }
    return res;
}
int main()
{
    ll m, ans, x = 2;
    while (cin >> m)
    {
        ans = qmi(3, m, mod);
        cout << ans << endl;
    }
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

gy-7

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值