aaaaa。。。拓展太难了.py

image

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100005];
ll b[100005];
ll n, h, k=0, ans;
bool cmp(ll a,ll b){
    return a>b;
}
ll kkk(ll h){
    for(ll i=0;i<n;i++){
        h-=b[i];
        if(h<=0){
            return i+ans+1;
        }
    }
}
int main(){
    cin >> n >> h;
    for(ll i=0;i<n;i++){
        cin >> a[i] >> b[i];
        k+=b[i];
        // cout << k << endl;
    }
    sort(a, a+n, cmp);
    sort(b, b+n, cmp);
    while(1){
        if(h<=0){
            cout << ans-1;
            return 0;
        }
        if(k>=h){
            cout << kkk(h);
            return 0;
        }
        h-=a[0];
        ans++;
    }
}

WA50分
我想冲做题排行榜,大佬能帮帮我吗 :smiling_face_with_tear:

2 个赞

我好像做过

1 个赞

在线的 @2345安全卫士
@刘子睿
这题我过了
我可以写一篇题解

加油!

1 个赞

所以我的思路错了么

1 个赞

解题思路:
由于题目保证
x_i < y_i
所以:
计算所有刀飞伤害
如果大于等于血量,则从大到小仍飞刀
否则留下一把砍伤最大的刀,其余刀飞出,留下的刀砍怪兽

没错啊,我的思路是对的

1 个赞

https://discourse.xinyoudui.com/t/topic/38874?u=冯俊骁
建议用结构体
你思路错了!
@刘子睿

只是这个反了而已

1 个赞

还是WA50

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100005];
ll b[100005];
ll n, h, k=0, ans;
bool cmp(ll a,ll b){
    return a>b;
}
ll kkk(ll h){
    for(ll i=0;i<n;i++){
        h-=b[i];
        if(h<=0){
            return i+ans+1;
        }
    }
}
int main(){
    cin >> n >> h;
    for(ll i=0;i<n;i++){
        cin >> a[i] >> b[i];
        k+=b[i];
        // cout << k << endl;
    }
    sort(a, a+n, cmp);
    sort(b, b+n, cmp);
    if(k>=h){
        cout << kkk(h);
    }
    else{
        for(ll i=0;i<n;i++){
            h-=b[i];
            ans++;
        }
        while(1){
            h-=a[0];
            ans++;
            if(h<=0){
                cout << ans;
                return 0;
            }
        }
    }
    return 0;
}
1 个赞

建议不要用什么kkk
下面直接模拟

1 个赞

好像真得用结构体,你把这一条加在题解上吧,不然A不了

1 个赞

好了吗?
@刘子睿

1 个赞

nope

1 个赞
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
    ll x, y;
};
node a[100005];
ll n, h, k=0, ans, maxx=-1;
bool cmp(node a,node b){
    return a.y>b.y;
}
ll kkk(ll h){
    for(ll i=0;i<n;i++){
        h-=a[i].y;
        if(h<=0){
            return i;
        }
    }
}
int main(){
    cin >> n >> h;
    for(ll i=0;i<n;i++){
        cin >> a[i].x >> a[i].y;
        k+=a[i].y;
        maxx=max(maxx, a[i].x);
        // cout << k << endl;
    }
    sort(a, a+n, cmp);
    if(k>=h){
        cout << kkk(h);
    }
    else{
        for(ll i=0;i<n;i++){
            if(maxx==a[i].x) continue;
            h-=a[i].y;
            ans++;
        }
        while(1){
            h-=maxx;
            ans++;
            if(h<=0){
                cout << ans;
                return 0;
            }
        }
    }
    return 0;
}

样例输出4

1 个赞

都说了别用函数

1 个赞
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
    ll x, y;
};
node a[100005];
ll n, h, k=0, ans, maxx=-1;
bool cmp(node a,node b){
    return a.y>b.y;
}
int main(){
    cin >> n >> h;
    for(ll i=0;i<n;i++){
        cin >> a[i].x >> a[i].y;
        k+=a[i].y;
        maxx=max(maxx, a[i].x);
        // cout << k << endl;
    }
    sort(a, a+n, cmp);
    if(k>=h){
        for(ll i=0;i<n;i++){
            h-=a[i].y;
            if(h<=0){
                cout <<  i;
            }
        }
    }
    else{
        for(ll i=0;i<n;i++){
            if(maxx==a[i].x) continue;
            h-=a[i].y;
            ans++;
        }
        while(1){
            h-=maxx;
            ans++;
            if(h<=0){
                cout << ans;
                return 0;
            }
        }
    }
    return 0;
}

先暂时撤回解决

所以还有人吗

当我没说