【Acwing】第61场周赛 题解


AcWing 4497. 分糖果 

输入样例:

4
1 3 4
1 10 100
10000000000000000 10000000000000000 10000000000000000
23 34 45

输出样例:

4
55
15000000000000000
51

#include <iostream>
using namespace std;

typedef long long LL;

int main()
{
    int T; cin >> T;
    while(T -- )
    {
        LL a, b, c;
        cin >> a >> b >> c;
        cout << (a + b + c) / 2 << endl;
    }
    return 0;
}

AcWing 4498. 指针 

输入样例1:

3
10
20
30

输出样例1:

YES

输入样例2:

3
10
10
10

输出样例2:

NO

输入样例3:

3
120
120
120

输出样例3:

YES

采用二进制枚举的方式来遍历所有的情况,最后进行判断 

#include <iostream>
#include <algorithm>

using namespace std;

const int N = 20;

int n;
int w[N];

int main()
{
    cin >> n;
    for(int i = 0; i <n; i ++ ) cin >> w[i];
    
    bool res = false;
    for(int i = 0; i < 1 << n; i ++ )
    {
        int s = 0;
        for(int j = 0; j < n; j ++ )
            if(i >> j & 1)
                s += w[j];
            else 
                s -= w[j];
        if(s % 360 == 0)
        {
            res = true;
            break;
        }
    }
    
    if(res) puts("YES");
    else puts("NO");
    
    return 0;
}

AcWing 4499. 画圆 

输入样例1:

5 3 3 1 1

输出样例1:

3.767767 3.767767 3.914214

输入样例2:

10 5 5 5 15

输出样例2:

5.000000 5.000000 10.000000

题目所给的三个要求为以下含义:

  1. 新的圆要在给定的圆内
  2. 给定坐标的点要在圆外
  3. 新的圆要求面积最大 

情况1:若给定坐标的点在圆外

        答案就是给定的圆 

情况2:若给定坐标的点在圆内

        答案就是给定点和圆心相连(延长线)所得到的最大圆


 

#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

const double eps = 1e-8;

int cmp(double x, double y)
{
    if(fabs(x - y) < eps) return 0;
    if(x < y) return -1;
    return 1;
}

int main()
{
    double r, x1, y1, x2, y2;
    cin >> r >> x1 >> y1 >> x2 >> y2;
    double dx = x1 - x2;
    double dy = y1 - y2;
    double d = sqrt(dx * dx + dy * dy);
    if(cmp(d, r) >= 0) printf("%lf %lf %lf\n", x1, y1, r);
    else
    {
        if(!cmp(x1, x2) && !cmp(y1, y2))
            printf("%lf %lf %lf\n", x1 + r / 2, y1, r / 2);
        else
        {
            double r2 = (r + d) / 2;
            double x = x2 + (x1 - x2) / d * r2;
            double y = y2 + (y1 - y2) / d * r2;
            printf("%lf %lf %lf\n", x, y, r2);
        }
            
    }
    return 0;
    
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

玄澈_

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

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

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

打赏作者

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

抵扣说明:

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

余额充值