8-7作业/重写ren_gao_zu

· · 个人记录

作业

P1325 雷达安装

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int n,d;
struct node{
    double x,y;
}a[1000005];
bool cmp(node l,node r){
    return l.y<r.y;
}
int ma=-1e9,ans;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>d;
    for(int i=1;i<=n;i++){
        int x1,y1;
        cin>>x1>>y1;
        if(y1>d){
            cout<<-1;
            return 0;
        }
        a[i].x=x1-sqrt(d*d-y1*y1);
        a[i].y=x1+sqrt(d*d-y1*y1);
    }
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;i++){
        if(a[i].x>ma){
            ma=a[i].y;
            ans++;
        }
    }cout<<ans;
    return 0;
}

P1250 种树

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
bool vis[1000005];
struct node{
    int b,e,t;
}a[1000005];
bool cmp(node x,node y){
    return x.e<y.e;
}
int n,m,ans;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>a[i].b>>a[i].e>>a[i].t;
    }
    sort(a+1,a+m+1,cmp);
    for(int i=1;i<=m;i++){
        int top=0;
        for(int j=a[i].b;j<=a[i].e;j++){
            if(vis[j]==1)top++;
        }
        if(top>=a[i].t)continue;
        for(int j=a[i].e;j>=a[i].b;j--){
            if(vis[j]==0){
                vis[j]=1;
                ans++,top++;
                if(top==a[i].t)break;
            }
        }
    }cout<<ans;
    return 0;
}

重写