2019暑假多校训练第十场 | 部分题解

忘记是谁出题了emm

反正到现在还莫得题解

比赛的时候做了两题

其实最后有机会把05也做出来的 但是出了bug

一直改啊改……

后来发现少了判断条件

 

09 Block Breaker

HDU 6699 bfs模拟

题目大意:给出 t 组样例,每一组样例包含矩阵大小n,m还有q次敲击位置

每一次敲击(x,y)该位置的小块就会掉落

如果矩阵内其他的block 上面或下面有一块为空 且 左边或下边有一块为空 则这块block 也会掉落

求每一次敲击(x,y)位置后有多少掉落的block

思路:当时理解题意后 就想着遍历一遍暴力就行了

但是要判断周围的block是否掉落 需要标记 并且用bfs会更快(还差点写错 丢人TAT

#include <bits/stdc++.h>
using namespace std;
int vis[2005][2005];
int a[5] = {1, 0, -1, 0};
int b[5] = {0, 1, 0, -1};
int ans = 0, n, m;
void bfs(int x, int y)
{
    vis[x][y] = 2;

    for (int i = 0; i < 4; i++) {
        int newx = x + a[i];
        int newy = y + b[i];
       // printf("%d %d\n", newx, newy);
        if (vis[newx][newy]==0&&newx >= 1 && newx <= n && newy >= 1 && newy <= m) {
            if ((vis[newx + 1][newy] == 2 || vis[newx - 1][newy] == 2) && (vis[newx][newy + 1] == 2 || vis[newx][newy - 1] == 2)) {
                ans++;
                bfs(newx, newy);
            }
        }
    }
}
int main()
{
    int t;
    scanf("%d", &t);
    while (t--) {
        memset(vis, 0, sizeof vis);
        int k, x, y;
        scanf("%d%d%d", &n, &m, &k);
        for (int i = 0; i < k; i++) {
            scanf("%d%d", &x, &y);
            if (vis[x][y] == 2) {
                ans = 0;
            } else {
                ans = 1;
                bfs(x, y);
            }
            printf("%d\n", ans);
        }
    }
    return 0;
}

 

03 Valentine's Day

HDU 6693 贪心思想

题目大意:给 t 组样例,每一组样例有 n 个礼物的高兴值,问怎么样使得送出的 k 个礼物让对方高兴一次的高兴值最高?

思路:先对高兴值进行排序,依次选择 1个,2个,3个……n个礼物,计算高兴值,取最大值即可

#include <bits/stdc++.h>
using namespace std;
double a[100005], b[100005];
double run(int x)
{
    double y , m = 0;
    if (x == 1) {
        return a[1];
    }
    for (int i = 1; i <= x; i++) {
        y =  a[i];
        for (int j = 1; j <= x; j++)
            if (i != j) {
                y = y * (1 - a[j]);
            }
        m += y;
    }
//    printf("%lf **\n",m);
    return m;
}
bool cmp(double a, double b)
{
    return a > b;
}
int main()
{
    int t, n;
    scanf("%d", &t);
    while (t--) {
        scanf("%d", &n);
        for (int i = 1; i <= n; i++) {
            scanf("%lf", &a[i]);
        }
        sort(a + 1, a + n + 1, cmp);
        double ans = 0;
        for (int i = 1; i <= n; i++) {
            double mm = run(i);
            if (ans < mm) {
                ans = mm;
            } else {
                break;
            }
        }
//        printf("%lf\n", run(2));
        printf("%.12lf\n", ans);
    }
    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值