9/8 small wind - race thinking problem-solving ideas

A

Meaning of the questions: the role of F (x) is to x + 1, if the last digit is zero zero removed, find the number of different F (n) a;

Outline of Solution: When only one when the number n F (n) must be 9, and then each treated separately, with a number of different 10-n% 10;

Code:

#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
long long n,flag=0;
while(~scanf("%lld",&n))
{
     if(n%10==0)
     {
         flag++;
         n++;
     }
     while(1)
     {
         if(n<10)
            break;
         long long x=n%10;
         if(x==0)
         {
             n/=10;
             continue;
         }
         flag+=10-x;
         n=n/10+1;
     }
     printf("%lld\n",flag+9);
}
return 0;
}

B

The meaning of problems: a string of numbers, can be modified according to its next row corresponding to the address numbers thereof, each number can only be modified once, the maximum value of the modified output

Problem-solving ideas: from left to right to start looking, if f (x)> x changed, otherwise unchanged

Code:

C

Question is intended: to the number n, the number of each of the two operations can be carried out, the operation 1: x + 2 / x-2, Operation 2: x + 1 / x-1, a free operation, the operation takes a 2, seek let all the same numbers minimum cost

Outline of Solution: Direct count the number, the minimum output of odd and even

Code:

#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
  int n,a[1000],i,b=0,c=0;
  while(~scanf("%d",&n))
  {
      for(i=0;i<n;i++)
        scanf("%d",&a[i]);
        for(i=0;i<n;i++)
        {
            if(a[i]%2==0)
                b++;
            else
                c++;
        }
        if(b<=c)
            printf("%d",b);
        else
            printf("%d",c);
  }
}

D

Days seeking bad day: the meaning of the questions

Problem-solving ideas: from back to front, the number of face value after heavy rain

Code:

#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
  int t,n,a[150000],flag,b,i,j,x;
  scanf("%d",&t);
  while(t--)
  {
      scanf("%d",&n);
      for(i=1;i<=n;i++) scanf("%d",&a[i]);
        b=a[n];
        flag=0;
        for(i=n-1;i>=1;i--)
        {
           if(a[i]>b)
            flag++;
            else
            {
                b=a[i];
            }
        }
      printf("%d\n",flag);
  }

}

E

 

Guess you like

Origin www.cnblogs.com/xiao20000605/p/11621799.html