天天看点

暑假训练赛20160719

F--Hot or Cold?

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Submit 

​​Status​​

Description

​​​​

John Smith, who is a member of Academy of Cold Manager (ACM), is in charge of a large-scale cold store. For him, it's a troublesome job. Whenever the temperature in the cold store is too hot or too cold for a long time, the goods will be damaged. And poor Mr. Smith will have to compensate for the loss of the store.

Therefore, Mr. Smith has installed an automatic temperature control system in the store. The system may control the temperature according to the input polynomial and the start time. At each moment, it tries to adjust the temperature equal to the value of the polynomial function. But Mr. Smith still feels worried. Since he could not know the effect beforehand how the system will regulate. At such a worrisome moment, it's lucky for him to call to remembrance that you, an excellent programmer, are willing to offer a program to help him. Making use of this program, he may simply input the polynomial and the parameters of the start time and the end time, and then he will be aware of the average temperature during this period. Now he is relieved from such a bothersome job.

Input

The input file may contain several data sets. Each data set begins with a line containing an integer n(n < 100), which specifies the highest power of the polynomial. A value of 0 for the power indicates the end of input, and this data set should not be processed. In each data set, the following line contains n + 1 real numbers, which tell the coefficients of the polynomial. The sequence of those coefficients is arranged according to the power of items from high to low in the polynomial. If an item of the polynomial does not exist, the corresponding coefficient is 0. And then follows a line consists of 2 real numbers s and e(s < e), indicating the start time and the end time.

Output

For each data set, compute t, the average temperature of the input polynomial from the start time to the end time. Print your answer as a single real number accurate to 3 decimal places on a line by itself. You should not print any more white spaces or blank lines in the output.

Sample Input

2

1.0 0.0 0.0

0.0 1.0

Sample Output

0.333

数学积分--

代码:

#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
double xi[120],s,kai,jie;
int main()
{
  int n;
  while (scanf("%d",&n),n)
  {
    for (int i=n+1;i>0;i--)
    {
      scanf("%lf",&xi[i]);
      xi[i]/=i;
    }
    scanf("%lf%lf",&kai,&jie);
    s=0.0;
    for (int i=n+1;i>0;i--)
    s+=xi[i]*(pow(jie,i)-pow(kai,i));
    s/=(jie-kai);
    printf("%.3lf\n",s);
  }
  return 0;
}      

I - Digital Rivers

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Submit 

​​Status​​

Description

​​​​

A digital river is a sequence of numbers where the number following n is n plus the sum of its digits. For example, 12345 is followed by 12360, since 1 + 2 + 3 + 4 + 5 = 15. If the first number of a digital river is k we will call it river k.

For example, river 480 is the sequence beginning {480, 492, 507, 519,...} and river 483 is the sequence beginning {483, 498, 519,...}.

Normal streams and rivers can meet, and the same is true for digital rivers. This happens when two digital rivers share some of the same values. For example: river 480 meets river 483 at 519, meets river 507 at 507, and never meets river 481.

Every digital river will eventually meet river 1, river 3 or river 9. Write a program that can determine for a given integer n the value where river n

Input

The input may contain multiple test cases. Each test case occupies a separate line and contains an integer n(1n16384). A test case wit h value of 0 for n

Output

For each test case in the input first output the test case number (starting from 1) as shown in the sample output. Then on a separate line output the line ``first meets river x at y". Here y is the lowest value where river n first meets river x (x = 1 or 3 or 9). If river nmeets river x at y for more than one value of x, output the lowest value.

Print a blank line between two consecutive test cases.

Sample Input

86

12345

Sample Output

Case #1

first meets river 1 at 101

Case #2

first meets river 3 at 12423

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MA 100000100
int he[MA];
int ji(int xx)
{
  int lp,jia;
  lp=xx;jia=0;
  while (xx)
  {
    jia+=xx%10;
    xx/=10;
  }
  lp+=jia;
  return lp;
}
int main()
{
  memset(he,0,sizeof(he));
  int shu;
  shu=9;
  while (shu<MA)
  {
    he[shu]=9;
    shu=ji(shu);
  }
  shu=3;
  while (shu<MA)
  {
    he[shu]=3;
    shu=ji(shu);
  }
  shu=1;
  while (shu<MA)
  {
    he[shu]=1;
    shu=ji(shu);
  }
  int n,lp=1;
  while (scanf("%d",&n),n)
  {
      if (lp>1)
      printf("\n");
    printf("Case #%d\n",lp++);
    while (n)
    {
      if (he[n])
      {
        printf("first meets river %d at %d\n",he[n],n);
        break;
      }
      n=ji(n);
      if (n>MA)
      {
        printf("%d   66",n);
        break;
      }
    }
  }
  return 0;
}