9/21 harder the more fortunate - thinking game (4.0) problem-solving ideas

A

Meaning of the questions: There are two water to 1 liter and 2-liter, given the number of both water and the price to buy a liter of water, seeking just the least money to buy the required number of liters flowers

Outline of Solution: determining a parity of water and 2 liters of water parity price lists appropriate calculation formula

 1 #include<stdio.h>
 2 #include<math.h>
 3 #include<iostream>
 4 #include<algorithm>
 5 using namespace std;
 6 int main()
 7 {
 8     long long q,n,a,b,minn;
 9     while(cin>>q)
10     {
11         while(q--)
12         {
13             cin>>n>>a>>b;
14             minn=a*n;
15             if(n%2==0)
 16              {
 17                  ow (b% 2 == 0 )
 18                  {
 19                      a = min (a, b / 2 * n);
20                  }
 21                  else 
22                  {
 23                      a = min (a, n / 2 * b);
24                  }
 25              }
 26              else 
27              {
 28                  ow (b% 2 == 0 )
 29                 {
 30                      a = min (a, b / 2 * (n- 1 ) + a);
31                  }
 32                  else 
33                  {
 34                      a = min (a, b * (n / 2 ) + a);
35                  }
 36              }
 37              COUTS << a << endl;
38          }
 39      }
 40    return  0 ;
41 }
View Code

B

Question is intended: to an array, the array is the number of power of 2, the same two numbers can be added back into the array, it is determined whether the occurrence 2048

Problem-solving ideas: tumble sort and build the array after the array keep adding new, cycle

 1 #include<stdio.h>
 2 #include<math.h>
 3 #include<iostream>
 4 #include<algorithm>
 5 using namespace std;
 6 int main()
 7 {
 8     int q,n,a[10000],i,b[10000];
 9     cin>>q;
10     while(q--)
11     {
12         cin>>n;
13         for(i=0;i<n;i++)
14             cin>>a[i];
15         for(i=0;i<10000;i++)
16             b[i]=0;
17         for(i=0;i<n;i++)
18         {
19            if(a[i]<=2048)
20             b[a[i]]++;
21         }
22         int flag=0;
23         for(i=1;i<=1024;i++)
24         {
25            while(b[i]>1)
26            {
27                b[i*2]++;
28                b[i]=b[i]-2;
29            }
30         }
31        if(b[2048])
32         cout<<"YES"<<endl;
33       else
34         cout<<"NO"<<endl;
35     }
36   return 0;
37 }
View Code

C

Question is intended: to an array, a number of sequentially removing from the array, is determined and the remaining odd and even equality

Problem-solving ideas: to obtain a sum of the parity before not, then sequentially scanning array, i representative of the i-th removed

And odd = (after the preceding odd and i + i, and the even-numbered)

Even and = (before and after the i + i and odd and even number)

 1 #include<stdio.h>
 2 #include<math.h>
 3 #include<iostream>
 4 #include<algorithm>
 5 using namespace std;
 6 int main()
 7 {
 8   long long n;
 9   int a[200010],i,sum1=0,sum2=0,x=0;
10   while(cin>>n)
11   {
12     for(i=1;i<=n;i++)
13         cin>>a[i];
14     for(i=1;i<=n;i++)
15     {
16         if(i%2!=0)
17              sum1+=a[i];
18         else
19             sum2+=a[i];
20     }
21     int newsum1=0,newsum2=0;
22     for(i=1;i<=n;i++)
23     {
24         if(i%2!=0)
25         {
26             sum1-=a[i];
27             if(sum1+newsum2==sum2+newsum1)
28                 x++;
29             newsum1+=a[i];
30         }
31         else
32         {
33             sum2-=a[i];
34             if(sum2+newsum1==sum1+newsum2)
35                 x++;
36             newsum2+=a[i];
37         }
38     }
39     cout<<x<<endl;
40   }
41   return 0;
42 }
View Code

E

Meaning of the questions: a team of three people to ICPC team success, there must be coder and mathematician, to number three the number of representatives of the three kinds of people, seeking the maximum number of teams can be composed of

Outline of Solution: Comparison coder and mathematician and three, and the number of minimum / 3 is also desired

 1 #include<stdio.h>
 2 #include<math.h>
 3 #include<iostream>
 4 #include<algorithm>
 5 using namespace std;
 6 int main()
 7 {
 8   int q,c,m,x,ans=0,minn;
 9   cin>>q;
10   while(q--)
11   {
12       cin>>c>>m>>x;
13       minn=c;
14       if(c+m+x<3)
15         cout<<"0" << endl;
 16        else 
17        {
 18            a = min (a, m);
 19            a = min (a, (c + m + x) / 3 )
 20            COUTS << a << endl;
 21        }
 22    }
 23    return  0 ;
 24 }
View Code

 

Guess you like

Origin www.cnblogs.com/xiao20000605/p/11626861.html
Recommended