C. Caesar Cipher
题目大意:给出T个测试案例,s所有字符通过加上一个特定的x转变为t, 要你求出s2,每个案例给出三组字符串s1,t1,t2
需要注意的是:字符串的字符可以为大写字符也可为小写字符 所以需要分大写和小写讨论
另外字母表的字母有26个字母 ASCII表:65~90为26个大写英文字母;97~122号为26个小写英文字母。
#include <stdio.h> #include <string.h> #include <iostream> using namespace std; int main() { int T; scanf("%d",&T); for(int h=1;h<=T;h++) { int n,m; scanf("%d%d",&n,&m); getchar(); char s1[55],s2[55],s3[55],s4[55]; scanf("%s",s1); scanf("%s",s2); scanf("%s",s3); int j=s1[0]-s2[0]; printf("Case #%d: ",h); for(int i=0;i<m;i++) { int t; if(s3[i]>='A'&&s3[i]<='Z') t=s3[i]-'A'+j; else t=s3[i]-'a'+j; t=(t+26)%26; s4[i]=t+'A'; cout<<s4[i]; } cout<<endl; } }
D. Take Your Seat---- 模拟找规律题
第一种情况:所有人按序号1到n顺序进场,多写几组案例 可发现答案为0.5
第二种情况是,所有人不按座号顺序入场,朵哈忘了座号,如果做别人的,别人也会随机做别的位置
分析如果 人1 是第 i 个登机的,那么登机的前 i − 1 人都能坐对,而且由于不是按顺序的Pn 的n 表示朵哈是第几个登机的
P =(Pm+Pm-1+....P2+P1)/m = (m+1)/(m*2)=(m/m+(m-1)/m+...+1/m)/m=(m+1)/(m*2)
需要注意的是:第一种情况当n=1,答案为1
1 #include <stdio.h> 2 #include <string.h> 3 #include <iostream> 4 using namespace std; 5 int main() 6 { 7 int T,a,b; 8 scanf("%d",&T); 9 for(int i=1;i<=T;i++) 10 { 11 scanf("%d%d",&a,&b); 12 double h=1.0*(b+1)/(2.0*b); 13 if(a==1) 14 printf("Case #%d: 1.000000 %.6lf\n",i,h); 15 else 16 printf("Case #%d: 0.500000 %.6lf\n",i,h); 17 } 18 }
B题-Rolling The Polygon
题意:其实就是求点q到各个顶点的半径与多边形各角的余角 然后将每个对应的弧长加起来
弧长=弧度*r acos(-1.0)180度弧度制
求弧度用余玄定理