1A,1B比较容易,直接贴代码了,
1C关于计算几何的一点知识,要比较清楚几个公式,我全给忘了,参照了写大牛的代码过了,
比较值得注意的是那个fgcd,求浮点型的最大公约数,最好设一个全局的esp=1e-4,即0.0001
当feq(a,0)或feq(b,0)即差小于esp则视为相等。
1B
1 #include<iostream> 2 #include<string> 3 #include<cmath> 4 #include<algorithm> 5 using namespace std; 6 7 int main() 8 { 9 int n; 10 string str; 11 cin>>n; 12 for(int i=0;i<n;i++) 13 { 14 int cnt1=0,cnt2=0,cnt3=0,cnt4=0; 15 cin>>str; 16 int flag=8888; 17 for(int j=0;j<str.length();j++) 18 { 19 if(cnt2==0&&(str[j]<'0'||str[j]>'9')) 20 { 21 cnt1++; 22 continue; 23 } 24 if(str[j]>='0'&&str[j]<='9'&&cnt3==0) 25 { 26 cnt2++; 27 continue; 28 } 29 if(cnt2>0&&(str[j]<'0'||str[j]>'9')) 30 { 31 cnt3++; 32 continue; 33 } 34 if(cnt3>0&&str[j]>='0'&&str[j]<='9') 35 { 36 cnt4++; 37 continue; 38 } 39 } 40 41 if(cnt3==0) 42 { 43 int c=0,r=0; 44 for(int i=0;i<cnt1;i++) 45 { 46 c+=pow((float)26,(float)cnt1-i-1)*(str[i]-'A'+1); 47 } 48 for(int i=0;i<cnt2;i++) 49 { 50 r+=pow((float)10,(float)cnt2-i-1)*(str[i+cnt1]-'0'); 51 } 52 53 cout<<"R"<<r<<"C"<<c<<endl; 54 } 55 else 56 { 57 int r=0,c=0; 58 string sstr; 59 for(int i=0;i<cnt2;i++) 60 { 61 r+=pow((float)10,(float)cnt2-1-i)*(str[1+i]-'0'); 62 } 63 for(int i=0;i<cnt4;i++) 64 { 65 c+=pow((float)10,(float)cnt4-1-i)*(str[1+cnt2+1+i]-'0'); 66 } 67 while(c>0) 68 { 69 int m=c%26; 70 if(m!=0) 71 { 72 sstr+=(char)(m+'A'-1); 73 c/=26; 74 } 75 else 76 { 77 sstr+='Z'; 78 c/=26; 79 c--; 80 } 81 82 } 83 reverse(&sstr[0],&sstr[sstr.length()]); 84 cout<<sstr<<r<<endl; 85 } 86 } 87 88 return 0; 89 }
1C
#include<cmath> #include<iostream> #include<cstdio> using namespace std; #define feq(a,b) (fabs((a)-(b))<1E-6) double Dis(double x1,double y1,double x2,double y2) { return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } double Area(double a,double b,double c) { double q=(a+b+c)/2; return sqrt(q*(q-a)*(q-b)*(q-c)); } double fgcd(double a,double b) { if(feq(a,0)) return b; if(feq(b,0)) return a; return fgcd(b,fmod(a,b)); } int main() { double x0,x1,x2,y0,y1,y2; cin>>x0>>y0>>x1>>y1>>x2>>y2; double a=Dis(x0,y0,x1,y1); double b=Dis(x0,y0,x2,y2); double c=Dis(x1,y1,x2,y2); double r=a*b*c/Area(a,b,c)/4; double A=acos((b*b+c*c-a*a)/2/b/c); double B=acos((a*a+c*c-b*b)/2/a/c); double C=acos((a*a+b*b-c*c)/2/a/b); //double A=2*asin(a/2/r); //double B=2*asin(b/2/r); //double C=2*asin(c/2/r); double e=acos(-1.0)/fgcd(A,fgcd(B,C)); double angle=2*acos(-1.0)/e; printf("%.8f ",sin(angle)*r*r*e/2); return 0; }