首页 > 代码库 > hdu2073-2078

hdu2073-2078

hdu2073

数学

技术分享
 1 #include<stdio.h>
 2 #include<math.h>
 3 double len(double x){
 4     return sqrt(x*x+(x+1)*(x+1));
 5 }
 6 
 7 int main(){
 8     int N;
 9     while(scanf("%d",&N)!=EOF){
10         for(int q=1;q<=N;q++){
11             double x1,y1,x2,y2;
12             double l=0;
13             scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
14             if(x1+y1==x2+y2){
15                 l=abs(y1-y2)*sqrt(2.0);
16             }
17             else{
18                 double a,b;
19                 if(x1+y1>x2+y2){
20                     double t;
21                     t=x1;x1=x2;x2=t;
22                     t=y1;y1=y2;y2=t;
23                 }
24                 a=x1+y1;b=x2+y2;
25                 int i;
26                 for(i=a;i<b;i++) l+=len(i);
27                 l+=((a+b)*(b-a-1)/2+y1+x2)*sqrt(2.0);
28             }
29             printf("%.3lf\n",l);
30 
31         }
32     }
33     return 0;
34 }
View Code



hdu2074

模拟

技术分享
 1 #include<stdio.h>
 2 
 3 char pic[81][81];
 4 
 5 int main(){
 6     int n,count=0;
 7     char a,b;
 8     while(scanf("%d %c %c",&n,&a,&b)!=EOF){
 9         if(count)printf("\n");
10         count++;
11         int i,j,h,l,c=1;
12         char m;
13         for(i=(n+1)/2;i>=1;i--){
14             h=i;l=n+1-i;
15             m=(c%2)?a:b;
16             c++;
17             for(j=h;j<=l;j++){
18                 pic[h][j]=pic[l][j]=pic[j][h]=pic[j][l]=m;
19             }
20         }
21         pic[1][1]=pic[1][n]=pic[n][1]=pic[n][n]= ;
22         if(n==1)pic[1][1]=a;
23         for(i=1;i<=n;i++){
24             for(j=1;j<=n;j++){
25                 printf("%c",pic[i][j]);
26             }
27             printf("\n");
28         }
29     }
30     return 0;
31 }
View Code

 

hdu2075

暴力

技术分享
 1 #include<stdio.h>
 2 int main()
 3 {
 4     int T;
 5     while (scanf("%d",&T)!=EOF)
 6     {
 7         int i;
 8         for (i=1;i<=T;i++)
 9         {
10             long long A,B;
11             scanf("%I64d%I64d",&A,&B);
12             if (A%B) printf("NO\n");
13             else printf("YES\n");
14         }
15     }
16     return 0;
17 }
View Code

 

hdu2076

计算时钟夹角,数学

技术分享
 1 #include<stdio.h>
 2 #include<math.h>
 3 
 4 int main(){
 5     int h,m,s,T;
 6     while(scanf("%d",&T)!=EOF){
 7         for(int q=1;q<=T;q++){
 8             scanf("%d%d%d",&h,&m,&s);
 9             if(h>=12)h-=12;
10             double a,b;
11             a=(30*h+30*m/60.0+30*s/3600.0);
12             b=(6*m+6*s/60.0);
13             double t=a-b;
14             if(t>180) t=360-t;
15             else if(t<-180) t=t+360;
16             else if(t<0) t=-t;
17             int p=t;
18             printf("%d\n",p);
19         }
20     }
21     return 0;
22 }
View Code



hdu2077

汉诺塔改,数学公式

技术分享
 1 #include<stdio.h>
 2 long long a[25],b[25],c[25],k[25];
 3 
 4 void fun(){
 5     int i;
 6     k[1]=2;
 7     for(i=2;i<=20;i++)k[i]=3*k[i-1]+2;
 8     a[1]=1;
 9     for(i=2;i<=20;i++)a[i]=k[i-1]+a[i-1]+1;
10     b[1]=1;
11     for(i=2;i<=20;i++)b[i]=b[i-1]+1+k[i-1];
12     c[1]=2;
13     for(i=2;i<=20;i++)c[i]=a[i-1]+2+b[i-1];
14 }
15 
16 
17 int main(){
18     fun();
19     int T;
20     while(scanf("%d",&T)!=EOF){
21         for(int q=1;q<=T;q++){
22             int n;
23             scanf("%d",&n);
24             printf("%I64d\n",c[n]);
25         }
26     }
27     return 0;
28 }
View Code

 

hdu2078

模拟

技术分享
 1 include<stdio.h>
 2 
 3 int main()
 4 {
 5     int T;
 6     while (scanf("%d",&T)!=EOF)
 7     {
 8         int i;
 9         for (i=1;i<=T;i++)
10         {
11             int n,m;
12             scanf("%d%d",&n,&m);
13             int max=100,j,min=100,a;
14             for (j=1;j<=n;j++)
15             {
16                 scanf("%d",&a);
17                 if (a<min) min=a;
18             }
19             printf("%d\n",(max-min)*(max-min));
20         }
21     }
22     return 0;
23 }
View Code

 

hdu2073-2078