第二次测试

来源:互联网 发布:软件安全工程师 编辑:程序博客网 时间:2024/05/11 00:42

之前做的第二套测试题目,刚刚做完第三套,现在就把第二套的日志补起来。


1058 Problem A:Help David


Description

Description 
One day, David finds a beautiful shape likes the black part of the following picture. 
 
That is a quadrilateral(四边形) ABCD, of which side length are all L. Now David wants to know that the total area of black part of the above picture. 

Input

The first line of input will contain an integer T (1≤T≤100), indicating the number of cases. Each case contains an integer L less than 10^6, which has been described above.

Output

For each case, you should print a line containing the case number (beginning with 1) and print the total area of black part of the above picture. Your answers should be processed with 2 digits after the decimal point.

Sample Input

241334

Sample Output

Case #1: 959.51Case #2: 63675.76

Source

第六届校赛


一:源代码:

#include <stdio.h>

#include<math.h>

#define PI acos(-1)

int main()

{

int n,i;

double s,a;

scanf("%d",&n);

for(i=1;i<=n;i++)

{

scanf("%lf",&a);

 s=a*a*PI/2-a*a;

printf("Case #%d: %2.1lf\n",i,s);

}

 return 0;   

}



二:结果截图



三:做题的思路:

算出阴影部分的面积,可以用一个以正方形边长为直径的半圆的面积减去一个以正方形对角线一半为边长的等腰直角三角形的面积,然后再乘以四。要注意定义边长的时候用double,并且是在一组中输入一个边长就输出一个面积,直到这一组的所有边长全部输入且面积输出完毕。

 

四:做题的过程:

第一,二次提交的时候,scanf中写成了scanf("%d\n",&n);后来发现scanf不能换行符号;

第三次,修改了这个问题中之后,还是过不了,PI定义的是3.1415927,感觉可能是定义错了。

第四,五次的时候,把定义改为了#define PI acos(-1);结果提示Presentation Error格式错误了。

在第六次提交的时候,才发现了不是定义的问题,发现这句话的格式有点问题,printf("Case #%d:%.2lf\n",i,s);

后来改成了printf("Case #%d: %.2lf\n",i,s);

最后就过了。

 

五:感受:做题的时候一定要注意输入输出的格式和标准写法,根据题目的意思来编写和修改程序。主要是格式问题,结果让我修改了这么多次……


    1083   IVXLCDM

Description

罗马数字是欧洲在阿拉伯数字(实际上是印度数字)传入之前使用的一种数码,现在应用较少.它的产生晚于中国甲骨文中的数码,更晚于埃及人的十进位数字.但是,它的产生标志着一种古代文明的进步. 

罗马数字用7个拉丁字母IVXLCDM和读数规则来表示数. 

I = 1 
V = 5 
X = 10 
L = 50 
C = 100 
D = 500 
M = 1000 

读数规则有以下三条 

(1)相同的数字连写,所表示的数等于这些数字相加得到的数,如:III就代表3; 
(2)小的数字在大的数字的右边,所表示的数等于这些数字相加得到的数.如:VIII =8,XII=12; 
(3)小的数字在大的数字的左边,所表示的数等于大数减小数得到的数,如IV=4.IX =9. 

注意不会出现IIX这样的情况,即每个数字左边最多有一个值比它小的数字. 

现在给你一些罗马数字表示下的数,要求你编写程序把它转换为用阿拉伯数字表示. 

Input

输入文件包含多组测试数据,每组测试数据一行,给出一个罗马数字表示的数,只包含IVXLCDM的合法组合,字母子间没有空白字符.确保转换得到的阿拉伯数字不会超过3000.

Output

对于每一组测试数据,对应输出其阿拉伯数字表示.

Sample Input

DXII

Sample Output

512

Hint

EOF结束输入

Source

2012暑期第二场个人赛



一:源代码

#include<stdio.h>

#include<string.h>

int main()

{

              char q[3000];

               int i,sum;

              int b[1000];

               b['I']=1;

               b['V']=5;

              b['X']=10;

               b['L']=50;

               b['C']=100;

               b['D']=500;

               b['M']=1000;

               while(scanf("%s",q)!=EOF)

              {

                  sum=b[q[0]];

                                              for(i=0;q[i]!=0;i++)

                                              {

                                                             if(b[q[i+1]]<=b[q[i]])sum=b[q[i+1]]+sum;

                                                            else

                                                                            sum=sum+b[q[i+1]]-2*b[q[i]];

                                              }

                                              printf("%d\n",sum);

               }

               return 0;

}


老实说这个题目很难,本来想用数组来一一对应的,但是发现实现不了,只能一一赋值,然后就按照要求直接写就可以了。




     1118 contest Timing


Description

Bessie the cow is getting bored of the milk production industry, and wants to switch to an exciting new career in computing. To improve her coding skills, she decides to compete in the on-line competitions. Since she notes that the contest starts on November 11, 2011 (11/11/11), she decides for fun to download the problems and begin coding at exactly 11:11AM on 11/11/11. 

Unfortunately, Bessie's time management ability is quite poor, so she wants to write a quick program to help her make sure she does not take longer than the 3 hour (180 minute) time limit for the contest. Given the date and time she stops working, please help Bessie compute the total number of minutes she will have spent on the contest. 

Input

* Line 1: This line contains 3 space-separated integers, D H M,specifying the date and time at which Bessie ends the contest. D will be an integer in the range 11..14 telling the day of the month; H and M are hours and minutes on a 24-hour clock(so they range from H=0,M=0 at midnight up through H=23,M=59 at 11:59 PM). 


Output

* Line 1: The total number of minutes spent by Bessie in the contest,or -1 if her ending time is earlier than her starting time.

Sample Input

12 13 14

Sample Output

1563

Hint

INPUT DETAILS: 
Bessie ends the contest on November 12, at 13:14 (that is, at 1:14 PM). 

OUTPUT DETAILS: 
Bessie ends the contest 1563 minutes after she starts.

Source



一:源代码

#include<stdio.h>

int main()

{

 int D,H,M,h,m,sum;

while(scanf("%d%d%d",&D,&H,&M)!=EOF)

{

     if(D==11&&H>=11&&M>=11||D>11)

     {

             if(D==11&&H>=11&&M>=11)

             sum=(H-11)*60+M-11;

             else 

             sum=(D-12)*24*60+H*60+M+13*60-11;

             printf("%d\n",sum);

      }

     else

      printf("-1\n");

 }

 return 0;

}


二:结果截图



三:思路和感受

这个题目就是计算结束竞赛到开始竞赛的时间差,由于日子,小时和分钟的大小都有很多情况,所以需要分开判断。

表示判断的时候的公式想了好久........




  1124   Hay Bales

Description

The cows are at it again! Farmer John has carefully arranged N (1 <= N <= 10,000) piles of hay bales, each of the same height. When he isn't looking, however, the cows move some of the hay bales between piles, so their heights are no longer necessarily the same. Given the new heights of all the piles, please help Farmer John determine the minimum number of hay bales he needs to move in order to restore all the piles to their original, equal heights.

Input

* Line 1: The number of piles, N (1 <= N <= 10,000). 

* Lines 2..1+N: Each line contains the number of hay bales in a single pile (an integer in the range 1...10,000).

Output

* Line 1: An integer giving the minimum number of hay bales that need to be moved to restore the piles to having equal heights.

Sample Input

421071

Sample Output

7

Hint

INPUT DETAILS: 
There are 4 piles, of heights 2, 10, 7, and 1. 

OUTPUT DETAILS: 
By moving 7 hay bales (3 from pile 2 to pile 1, 2 from pile 2 to pile 4, 2 from pile 3 to pile 4), we can make all piles have height 5.

Source


一:源代码

#include<stdio.h>

int main()

{

              int N,i,a[10000],h=0,j=0;

               while(scanf("%d",&N)!=EOF)

               {

                               for(i=0;i<N;i++)

                               {

                                              scanf("%d",&a[i]);

                                              h=a[i]+h;

                               }

                               h=h/N;

                              for(i=0;i<N;i++)

                               {

                                  if(a[i]>h)

                                                 j=a[i]-h+j;

                               }

                               printf("%d\n",j);

               }

                               return 0;

 }


二:结果截图




三:思路和感受

这个题的思路实际上就是先求出平均值,然后找出比平均值大的数字,求出它们和平均值的差的和。

计算的方法特别简单,就是对于题目的理解有点小困难。开始的时候一直没看懂,后来看了事例之后才理解的。


1170 素数求和

Description

据说这是一个非常难的问题: 
给出n(1 < n <= 1000000)个数,要求你计算出这些数中所有素数的和。 
(素数:指在一个大于1的自然数中,除了1和此整数自身外,不能被其他自然数整除的数。)

Input

首先给出一个数n,然后有n个整数 
所有整数不大于1000000 

Output

输出这n个数中素数的和

Sample Input

53 5 7 8 9

Sample Output

15



一:源代码

#include<stdio.h>#include<string.h>#define MAX 1000001int w[MAX];int main(){int i,n,a,p;__int64 s;memset(w,0,sizeof(w));w[0]=1;    w[1]=1;for(i=2;i<MAX/2;i++){if(w[i]==0)    {    for(p=2*i;p<MAX;p=p+i)w[p]=1;}}while(scanf("%d",&n)!=EOF){s=0;for(i=0;i<n;i++){scanf("%d",&a);           if(w[a]==0)s=s+a;}printf("%I64d\n",s);}return 0;}


二:结果截图



三:思路和感受

这个题目是素数求和,很简单的算法,但是每次都是说超时,通过不了,后来请教了他们,可以用下表判断法。


感觉这次的题目都特别的难,很考算法和理解能力,就像最后一题,要想不超时,各种方法都试过了还是不能,

看来ACM还是很考思维的啊。还是要多锻炼。



原创粉丝点击