8.10晚上综合测试 总结
T5
错误原因
没写完
思路
从坐标轴上找到能覆盖的这个点的最左的和最右的点。然后就变成了最小点覆盖。
代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,r;
struct node{
double l,r;
}e[110];
int len;
void cal(int x,int y){
double deta;
deta=sqrt(r*r-y*y);
e[++len].l=x*1.0-deta;
e[len].r=x*1.0+deta;
}
bool cmp(node x,node y){
return x.r<y.r;
}
int ans;
double last;
int x;
int y;
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n>>r;
for(int i=1;i<=n;i++){
cin>>x>>y;
cal(x,y);
}
sort(e+1,e+len+1,cmp);
last=e[1].r;
ans++;
for(int i=2; i<=len;i++)
if(last<e[i].l)ans++,last=e[i].r;
cout<<ans;
return 0;
}
T6
错误原因
时间不够,只来得及写一个暴力代码。
思路
树状数组板子题,把区间加一然后判断奇偶性。
代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m;
int c[500005];
int a[500005];
int lowbit(int x){
return x&-x;
}
int get(int x){
int sum=0;
while(x){
sum+=c[x];
x-=lowbit(x);
}
return sum;
}
void modify(int x,int y){
while(x<=n){
c[x]+=y;
x+=lowbit(x);
}
return;
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n>>m;
while(m--){
int opt;
cin>>opt;
if(opt==1){
int l,r;
cin>>l>>r;
modify(l,1);
modify(r+1,-1);
}else{
int x;
cin>>x;
cout<<get(x)%2<<'\n';
}
}
return 0;
}
```