IOS遗忘的知识

Piggy-Bank

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 7626   Accepted: 3665

Description

Before ACM can do anything, a budget must be prepared and the necessary financial support obtained. The main income for this action comes from Irreversibly Bound Money (IBM). The idea behind is simple. Whenever some ACM member
has any small money, he takes all the coins and throws them into a piggy-bank. You know that this process is irreversible, the coins cannot be removed without breaking the pig. After a sufficiently long time, there should be enough cash in the piggy-bank to
pay everything that needs to be paid.

But there is a big problem with piggy-banks. It is not possible to determine how much money is inside. So we might break the pig into pieces only to find out that there is not enough money. Clearly, we want to avoid this unpleasant situation. The only possibility
is to weigh the piggy-bank and try to guess how many coins are inside. Assume that we are able to determine the weight of the pig exactly and that we know the weights of all coins of a given currency. Then there is some minimum amount of money in the piggy-bank
that we can guarantee. Your task is to find out this worst case and determine the minimum amount of cash inside the piggy-bank. We need your help. No more prematurely broken pigs!

Input

The input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case begins with a line containing two integers E and F. They indicate the weight of an empty pig and of the pig
filled with coins. Both weights are given in grams. No pig will weigh more than 10 kg, that means 1 <= E <= F <= 10000. On the second line of each test case, there is an integer number N (1 <= N <= 500) that gives the number of various coins used in the given
currency. Following this are exactly N lines, each specifying one coin type. These lines contain two integers each, Pand W (1 <= P <= 50000, 1 <= W <=10000). P is the value of the coin in monetary units, W is it‘s weight in grams.

Output

Print exactly one line of output for each test case. The line must contain the sentence "The minimum amount of money in the piggy-bank is X." where X is the minimum amount of money that can be achieved using coins with the given
total weight. If the weight cannot be reached exactly, print a line "This is impossible.".

Sample Input

3
10 110
2
1 1
30 50
10 110
2
1 1
50 30
1 6
2
10 3
20 4

Sample Output

The minimum amount of money in the piggy-bank is 60.
The minimum amount of money in the piggy-bank is 100.
This is impossible.

完全背包。。。。。

AC代码如下:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<climits>
#define M 100005
using namespace std;
int main()
{
    int m,e,f,t;
    int i,j;
    int a[M],b[M],dp[M];
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&e,&f);
        f-=e;
        scanf("%d",&m);
        for(i=1;i<=m;i++)
            scanf("%d%d",&a[i],&b[i]);
        for(i=1;i<=f;i++)
            dp[i]=INT_MAX/2;//实验证明背包还是不要取最大了
        //printf("%d\n",dp[f]);
        for(i=1,dp[0]=0;i<=m;i++)
        {
            for(j=b[i];j<=f;j++)
                if(dp[j]>dp[j-b[i]]+a[i])
                    dp[j]=dp[j-b[i]]+a[i];
        }
        if(dp[f]!=INT_MAX/2)
        printf("The minimum amount of money in the piggy-bank is %d.\n",dp[f]);
        else
            printf("This is impossible.\n");
    }
    return 0;
}

IOS遗忘的知识

时间: 2024-09-30 07:02:49

IOS遗忘的知识的相关文章

iOS底层基础知识-文件目录结构

一:iOS沙盒知识 出于安全考虑,iOS系统把每个应用以及数据都放到一个沙盒(sandbox)里面,应用只能访问自己沙盒目录里面的文件.网络资源等(也有例外,比如系统通讯录.照相机.照片等能在用户授权的情况下被第三方应用访问) 1:MyApp.app 该目录包含了应用程序本身的数据,程序打包的时候的资源文件和一些本地文件就是存放在这个目录下的. 程序的可执行程序.plist文件也在这个目录下. 这个目录不会被iTunes同步 2:Documents 使用这个目录来保存关键数据.关键数据指那些应用

iOS开发基础知识--碎片32

 iOS开发基础知识--碎片32 1:动画属性UIViewAnimationOptions说明 a:常规动画属性设置(可以同时选择多个进行设置) UIViewAnimationOptionLayoutSubviews:动画过程中保证子视图跟随运动. UIViewAnimationOptionAllowUserInteraction:动画过程中允许用户交互. UIViewAnimationOptionBeginFromCurrentState:所有视图从当前状态开始运行. UIViewAnimat

iOS开发基础知识--碎片1

iOS开发基础知识--碎片1  一:NSString与NSInteger的互换 NSInteger转化NSString类型:[NSString stringWithFormat: @"%d", NSInteger]; NSString转化 NSInteger类型:NSInteger = [NSString intValue]; *其它几个同理 [NSString boolValue].[NSString floatValue].[NSString doubleValue] 二:Obje

iOS开发基础知识--碎片3

iOS开发基础知识--碎片3  iOS开发基础知识--碎片3 十二:判断设备 //设备名称 return [UIDevice currentDevice].name; //设备型号,只可得到是何设备,无法得到是第几代设备 return [UIDevice currentDevice].model; //系统版本型号,如iPhone OS return [UIDevice currentDevice].systemVersion; //系统版本名称,如6.1.3 return [UIDevice

iOS开发基础知识--碎片2

iOS开发基础知识--碎片2 六:获得另一个控件器,并实现跳转 UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; UIViewController *registerViewController = [mainStoryboard instantiateViewControllerWithIdentifier:@"registerView

iOS开发基础知识--碎片23

iOS开发基础知识--碎片23  1:关于UITableView中关于行重复加载的问题 在Cell里重写prepareForReuse,对一些控件进行清空: 比较简单: -(void)prepareForReuse{ [super prepareForReuse]; _content_label.text = nil; _time_date_label.text = nil; _name_label.text = nil; _career_label.text = nil; } 下面这个是我在c

iOS开发基础知识--碎片21

iOS开发基础知识--碎片21  1:[UIScreen mainScreen].scale知识点 当屏幕分别为640x940时[[UIScreen mainScreen] scale]=2.0 当屏幕分别为320x480时[[UIScreen mainScreen] scale]=1.0 2:如何正确的绘制1像素的线 #define SINGLE_LINE_WIDTH (1 / [UIScreen mainScreen].scale) #define SINGLE_LINE_ADJUST_OF

iOS开发基础知识--碎片24

 iOS开发基础知识--碎片24 1:兼容字体大小6plue跟它以下的区别 #define FONT_COMPATIBLE_SCREEN_OFFSET(_fontSize_) [UIFont systemFontOfSize:(_fontSize_ *([UIScreen mainScreen].scale) / 2)] 在iPhone4~6中,缩放因子scale=2:在iPhone6+中,缩放因子scale=3 运用时: myLabel.font=FONT_COMPATIBLE_SCREEN_

iOS开发基础知识--碎片6

iOS开发基础知识--碎片6  三十三:IOS多视图跳转方法 第一种: 跳转:[self presentModalViewController:control animated:YES]; 返回:[self dismissModalViewControllerAnimated:YES]; 第二种: 跳转:[self.navigationController pushViewController:subTableViewController animated:YES]; 返回:[self.navi