ningago @ 2022-06-12 21:26:45
求调,其实也不用大佬动脑子,找不同就行了,因为改的跟大佬的代码几乎一模一样了。
不是eps的问题
WA:
#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;
#define pow2(x) ((x) * (x))
#define ld long double
const ld cc = cos(0.4);
const ld ss = sin(0.4);
const ld eps = 1e-6;
#define N 5000010
int n;
struct bubble
{
ld x,y,r;
bool operator < (const bubble &a)const
{
return y < a.y;
}
}c[N];
struct cmp{bool operator()(int x,int y){return c[x].y<c[y].y;}};
set<int,cmp> st;
set<int,cmp>::iterator it;
struct LINE
{
ld x;
int id,op;
bool operator < (const LINE &a)const
{
return x < a.x;
}
bool operator > (const LINE &a)const
{
return x > a.x;
}
}line[N];
int linecnt,ans;
map <pair<bubble,bubble>,bool> vis;
int main()
{
freopen("bubble.in","r",stdin);
freopen("bubble.out","w",stdout);
scanf("%d",&n);
for(int i = 1;i <= n;i++)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
c[i].x = cc * + ss * y;
c[i].y = -ss * x + cc * y;
c[i].r = 1.0 * z;
line[++linecnt] = (LINE){c[i].x - c[i].r,i,1};
line[++linecnt] = (LINE){c[i].x + c[i].r,i,-1};
}
std::sort(line + 1,line + linecnt + 1);
for(int i = 1;i <= linecnt;i++)
{
if(line[i].op == 1)
{
it = st.upper_bound(line[i].id);
if(it != st.end())
{
int pre = *it;
//printf("%.2LF %.2LF %.2LF : %.2LF %.2LF %.2LF\n",c[pre].x,c[pre].y,c[pre].r,c[line[i].id].x,c[line[i].id].y,c[line[i].id].r);
//printf("%.8LF ^ 2 + %.8LF ^ 2\n",(c[pre].x - c[line[i].id].x),(c[pre].y - c[line[i].id].y));
//printf("rdis = %.6LF\n",pow2(c[pre].r + c[line[i].id].r));
if(fabs(sqrt(pow2(c[pre].x - c[line[i].id].x) + pow2(c[pre].y - c[line[i].id].y)) - (c[pre].r + c[line[i].id].r)) <= eps)
{
if(!vis[make_pair(c[line[i].id],c[pre])])
{
ans++;
vis[make_pair(c[line[i].id],c[pre])] = 1;
vis[make_pair(c[pre],c[line[i].id])] = 1;
}
}
}
if(it != st.begin())
{
it--;
int suc = *it;
//printf("%.2LF %.2LF %.2LF : %.2LF %.2LF %.2LF\n",c[suc].x,c[suc].y,c[suc].r,c[line[i].id].x,c[line[i].id].y,c[line[i].id].r);
//printf("%.8LF ^ 2 + %.8LF ^ 2\n",(c[suc].x - c[line[i].id].x),(c[suc].y - c[line[i].id].y));
//printf("rdis = %.6LF\n",pow2(c[suc].r + c[line[i].id].r));
if(fabs(sqrt(pow2(c[suc].x - c[line[i].id].x) + pow2(c[suc].y - c[line[i].id].y)) - (c[suc].r + c[line[i].id].r)) <= eps)
{
if(!vis[make_pair(c[line[i].id],c[suc])])
{
ans++;
vis[make_pair(c[line[i].id],c[suc])] = 1;
vis[make_pair(c[suc],c[line[i].id])] = 1;
}
}
}
st.insert(line[i].id);
}
else
{
it = st.find(line[i].id);
if(it != st.begin()){
int pre = *--it;
++it;
++it;
if(it != st.end())
{
int suc = *it;
if(fabs(sqrt(pow2(c[suc].x - c[pre].x) + pow2(c[suc].y - c[line[i].id].y)) - (c[suc].r + c[line[i].id].r)) <= eps)
{
if(!vis[make_pair(c[pre],c[suc])])
{
ans++;
vis[make_pair(c[pre],c[suc])] = 1;
vis[make_pair(c[suc],c[pre])] = 1;
}
}
}
it--;
}
st.erase(it);
}
}
printf("%d\n",ans);
return 0;
}
dalao's AC:
#include<bits/stdc++.h>
using namespace std;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if (ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
typedef long double ld;
const ld _0=1e-8,_s=std::sin(0.4),_c=std::cos(0.4);
int ans=0;
struct cir{
ld x,y,r;
}cs[500010];
struct event{
ld x;
int id,type;
}es[1000010];
pair<int,int>as[1500050];
int ap=0;
bool operator<(event a,event b){
return a.x<b.x;
}
#define pow2(x) ((x) * (x))
struct cmp{bool operator()(int x,int y){return cs[x].y<cs[y].y;}};
set<int,cmp>line;
void chk(int a,int b){
ld x=cs[a].x-cs[b].x,y=cs[a].y-cs[b].y;
printf("%.8LF ^2 + %.8LF ^ 2\n",x,y);
printf("%.8LF\n",sqrt(x*x+y*y)-(cs[a].r + cs[b].r));
if(std::fabs(std::sqrt(x*x+y*y)-cs[a].r-cs[b].r)<_0){
if(a>b){int c=a;a=b;b=c;}
as[ap++]=std::make_pair(a,b);
}
}
int main(){
int n=read();
for(int i=0;i<n;i++){
int x=read(),y=read(),r=read();
cs[i].x=_c*x+_s*y;
cs[i].y=-_s*x+_c*y;
cs[i].r=r;
es[i<<1]=(event){cs[i].x-cs[i].r,i,1};
es[i<<1^1]=(event){cs[i].x+cs[i].r,i,0};
}
n<<=1;
sort(es,es+n);
for(int i=0;i<n;i++){
event w=es[i];
if(w.type){
std::set<int,cmp>::iterator it=line.upper_bound(w.id);
if(it!=line.end())chk(*it,w.id);
if(it!=line.begin())--it,chk(*it,w.id);
line.insert(w.id);
}else{
std::set<int,cmp>::iterator it=line.find(w.id);
if(it!=line.begin()){
int a=*--it;++it;++it;
if(it!=line.end())chk(*it,a);
--it;
}
line.erase(it);
}
}
sort(as,as+ap);
if(ap)
ans=1;
for(int i=1;i<ap;i++)if(as[i]!=as[i-1])++ans;
printf("%d",ans);
return 0;
}
原题(没用,应该没几个人做过吧,所以找不同就好了~
by Engulf @ 2022-06-12 21:29:35
https://csacademy.com/app/diffing_tool/
by ningago @ 2022-06-12 21:30:45
@TMJYH09
(我要需要这样找不同我还不如抄个题解