题目里说两路径长度不等,为啥会出现这种问题
#include <bits/stdc++.h> using namespace std; typedef long long ll; inline ll read() { char c = getchar(); ll x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } const int inf=0x3f3f3f3f; const int maxn=1e5+50; double x[maxn],y[maxn]; int main(){ double xc,yc,x1,y1,x2,y2; int cnt=1; while(cin>>xc>>yc>>x1>>y1>>x2>>y2){ if(xc==0&&yc==0&&x1==0&&y1==0&&x2==0&&y2==0) break; int n; cin>>n; for(int i=0;i<n;i++) cin>>x[i]>>y[i]; x[n]=x2,y[n]=y2; double len=sqrt((x[0]-x1)*(x[0]-x1)+(y[0]-y1)*(y[0]-y1)); for(int i=1;i<=n;i++){ len+=sqrt((x[i-1]-x[i])*(x[i-1]-x[i])+(y[i-1]-y[i])*(y[i-1]-y[i])); } double r=sqrt((x1-xc)*(x1-xc)+(y1-yc)*(y1-yc)); double c2=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2); double cir=acos((2*r*r-c2)/(2*r*r))*r; cout<<"Case #"<<cnt++<<": "; if(cir>len) cout<<"Watch out for squirrels!"<<endl;//这样wa else cout<<"Stick to the Circle."<<endl; cout<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; inline ll read() { char c = getchar(); ll x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } const int inf=0x3f3f3f3f; const int maxn=1e5+50; double x[maxn],y[maxn]; int main(){ double xc,yc,x1,y1,x2,y2; int cnt=1; while(cin>>xc>>yc>>x1>>y1>>x2>>y2){ if(xc==0&&yc==0&&x1==0&&y1==0&&x2==0&&y2==0) break; int n; cin>>n; for(int i=0;i<n;i++) cin>>x[i]>>y[i]; x[n]=x2,y[n]=y2; double len=sqrt((x[0]-x1)*(x[0]-x1)+(y[0]-y1)*(y[0]-y1)); for(int i=1;i<=n;i++){ len+=sqrt((x[i-1]-x[i])*(x[i-1]-x[i])+(y[i-1]-y[i])*(y[i-1]-y[i])); } double r=sqrt((x1-xc)*(x1-xc)+(y1-yc)*(y1-yc)); double c2=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2); double cir=acos((2*r*r-c2)/(2*r*r))*r; cout<<"Case #"<<cnt++<<": "; if(cir<len) cout<<"Stick to the Circle."<<endl;//这样能过 else cout<<"Watch out for squirrels!"<<endl; cout<<endl; } return 0; }
全部评论
(0) 回帖