专栏文章
8-7作业/重写ren_gao_zu
个人记录参与者 1已保存评论 0
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @miogpgrw
- 此快照首次捕获于
- 2025/12/02 18:55 3 个月前
- 此快照最后确认于
- 2025/12/02 18:55 3 个月前
作业
P1325 雷达安装
CPP#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 种树
CPP#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;
}
重写
无
相关推荐
评论
共 0 条评论,欢迎与作者交流。
正在加载评论...