Blue Bridge Cup 2013- provincial tournament -C / C ++ - A group of eight questions

Topic
Title: The number of buy

    Xiao Ming opened a candy store. He ingenuity: fruit sugar packets into a packet 4 and 7 two kinds of a packet. Candy unpacking can not sell.

    When the children to buy sugar, he used to combine the two packaging. Of course, some combination of the number of candy is not out, for example, to buy 10 sugar.

    You can use the computer test, in which case the package, can not buy the maximum number is 17. Any number greater than 17 can be used out of 4 and 7 in combination.

    The title is required during two the number of packages are known, the combination can not find out the maximum number.

Input:
two positive integer representing the number of teeth of each sugar packaging (not more than 1000)

Required output:
a positive integer representing the maximum number of sugar can not buy

No need to consider the situation no solution

For example:
a user input:
47
program should output:
17

Another example:
a user input:
35
program should output:
7


Resources for:
peak memory consumption <64M
the CPU consumption <3000ms


Please strictly follow the requirements of output, not superfluous to print something like: "Please enter ..." unwanted content.

All source code in a single file, through debugging, submit the copy source.

Note: main function needs to return 0
Note: Use only ANSI C / ANSI C ++ standard, do not call a special function depends on the build environment or operating system.
Note: all dependent functions must explicitly #include <xxx>, can not be provided by the project source file header files commonly omitted.

When you submit, pay attention to select the desired type of compiler.

Code 1

 

 1 /*2013-蓝桥-A-8 完全背包*/
 2 #include<iostream>
 3 #include<cstring>
 4 using namespace std;
 5 int dp[1000*1000+5];
 6 int main(){
 7     memset(dp,0,sizeof(dp));
 8     int in_num[2];
 9     cin>>in_num[0]>>in_num[1];
10     int upper=in_num[0]*in_num[1];
 . 11      DP [in_num [ 0 ]] = . 1 ;
 12 is      DP [in_num [ . 1 ]] = . 1 ;
 13 is      for ( int I = 0 ; I < 2 ; I ++ ) {
 14          for ( int J = in_num [I]; J <= Upper; J ++ ) {
 15              dp [J] + = dp [J-in_num [I]]; // profile dp array prior to use in the introduction of the latter information 
16          }
 . 17      }
 18 is      int in Flag = 0 ;
 . 19      int ANS;
 20 is      for (int i=upper;(i>0)&&(!flag);--i){
21         if(!dp[i]){
22             ans=i;
23             flag=1;
24         }
25     } 
26     cout<<ans<<endl;
27     
28 }

 

Code 2

 

1  / * 2013- blue bridge -A-8 Number Theory * / 
2 #include <the iostream>
 . 3  the using  namespace STD;
 . 4  int main () {
 . 5      int A, B;
 . 6      CIN >> A >> B; 
 . 7      COUT << * BAB << a endl;
 . 8      // number of the maximum number of two can not be combined for subtracting the product of two numbers and the sum of two 
9 }

 

 

 

 

Guess you like

Origin www.cnblogs.com/memocean/p/12401899.html
Recommended