三角形面积公式 底高=底高
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
const ll mod=1e9+7;
const int INF=0x3f3f3f3f;
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define pb push_back
ll T;
double xa,ya,xr,r,n;
double y,c;
double ans;
int main(){
IO;
cin>>T;
while(T--){
cin>>xa>>ya>>xr>>r>>n;
ans=0;
while(n--){
cin>>y>>c;
y-=ya;
double d=((xa-xr)*(xa-xr)*y*y)/(xa*xa+y*y);
if(d<=r*r)
ans+=max(0.0,c-((xa-xr)*(xa-xr)-r*r));//-a*(a+b)=a*a+ab=切线的方
else
ans+=c;
}
printf("%.0f\n",ans);
}
return 0;
}
相似三角形
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
const ll mod=1e9+7;
const int INF=0x3f3f3f3f;
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define pb push_back
ll T;
double xa,ya,xr,r,n;
double ans;
double y,c;
int main(){
IO;
cin>>T;
while(T--){
cin>>xa>>ya>>xr>>r>>n;
ans=0;
while(n--){
cin>>y>>c;
double q=(xa-xr)*(xa-xr)-r*r; //a*(a+b)=切线的方
//相似三角形 三角形面积公式
double ym=xa*xa*r*r/q;//相切时的ym
if(ym>=(y-ya)*(y-ya))
ans+=max(0.0,c-q);
else
ans+=c;
}
printf("%.0f\n",ans);
}
return 0;
}