zoukankan      html  css  js  c++  java
  • acm寒假特辑1月24日 HDU

    A - 1 CodeForces - 500A (签到)

    New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1 × n board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.

    So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of n - 1 positive integers a1, a2, …, an - 1. For every integer i where 1 ≤ i ≤ n - 1 the condition 1 ≤ ai ≤ n - i holds. Next, he made n - 1 portals, numbered by integers from 1 to n - 1. The i-th (1 ≤ i ≤ n - 1) portal connects cell i and cell (i + ai), and one can travel from cell i to cell (i + ai) using the i-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (i + ai) to cell i using the i-th portal. It is easy to see that because of condition 1 ≤ ai ≤ n - i one can’t leave the Line World using portals.

    Currently, I am standing at cell 1, and I want to go to cell t. However, I don’t know whether it is possible to go there. Please determine whether I can go to cell t by only using the construted transportation system.

    Input
    The first line contains two space-separated integers n (3 ≤ n ≤ 3 × 104) and t (2 ≤ t ≤ n) — the number of cells, and the index of the cell which I want to go to.

    The second line contains n - 1 space-separated integers a1, a2, …, an - 1 (1 ≤ ai ≤ n - i). It is guaranteed, that using the given transportation system, one cannot leave the Line World.

    Output
    If I can go to cell t using the transportation system, print “YES”. Otherwise, print “NO”.

    Examples
    Input
    8 4
    1 2 1 2 1 2 1
    Output
    YES
    Input
    8 5
    1 2 1 2 1 1 1
    Output
    NO
    Note
    In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.

    In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can’t visit the cell 5, which we want to visit.

    设a[i]为第i个房子能到的距离(且只能是这个距离),问你是否能到达t。模拟,一步步往前走。

    #include<iostream>
    using namespace std;
    int main()
    {
    	int n, t, a[30005],judge = 0;
    	cin >> n >> t;
    	for (int i = 1; i < n; i++)
    		cin >> a[i];
    	for (int i = 1; i <= t;)
    	{
    		if (i == t)
    		{
    			judge = 1;
    			break;
    		}
    		i += a[i];
    	}
    	if (judge == 1)
    		cout << "YES" << endl;
    	else
    		cout << "NO" << endl;
        return 0;
    }
    

    C - 3 HDU - 2191(背包)

    急!灾区的食物依然短缺!
    为了挽救灾区同胞的生命,心系灾区同胞的你准备自己采购一些粮食支援灾区,现在假设你一共有资金n元,而市场有m种大米,每种大米都是袋装产品,其价格不等,并且只能整袋购买。
    请问:你用有限的资金最多能采购多少公斤粮食呢?

    后记:
    人生是一个充满了变数的生命过程,天灾、人祸、病痛是我们生命历程中不可预知的威胁。
    月有阴晴圆缺,人有旦夕祸福,未来对于我们而言是一个未知数。那么,我们要做的就应该是珍惜现在,感恩生活——
    感谢父母,他们给予我们生命,抚养我们成人;
    感谢老师,他们授给我们知识,教我们做人
    感谢朋友,他们让我们感受到世界的温暖;
    感谢对手,他们令我们不断进取、努力。
    同样,我们也要感谢痛苦与艰辛带给我们的财富~

    Input
    输入数据首先包含一个正整数C,表示有C组测试用例,每组测试用例的第一行是两个整数n和m(1<=n<=100, 1<=m<=100),分别表示经费的金额和大米的种类,然后是m行数据,每行包含3个数p,h和c(1<=p<=20,1<=h<=200,1<=c<=20),分别表示每袋的价格、每袋的重量以及对应种类大米的袋数。
    Output
    对于每组测试数据,请输出能够购买大米的最多重量,你可以假设经费买不光所有的大米,并且经费你可以不用完。每个实例的输出占一行。
    Sample Input
    1
    8 2
    2 100 4
    4 100 2
    Sample Output
    400

    花钱买米,背包问题。但是每种大米都是有限袋数的。

    #include <iostream>
    #include<cstdio>
    using namespace std;
    #define max(a,b) (a>b?a:b)
    int main()
    {
    	int c, n, m, i, j, k, maxweight =0;//n为现金,m为米的种类
    	int cost[105], wight[105], number[105], dp[105];
    	cin >> c;
    	while (c--)
    	{
    		maxweight = 0;
    		cin >> n >> m;
    		for (int i = 1; i <= m; i++)
    		{
    			scanf_s("%d%d%d", &cost[i], &wight[i], &number[i]);
    		}
    		memset(dp, 0, sizeof(dp));//初始化数组
    		for (i = 1; i <= m; i++)
    		{
    			for (j = n; j >= cost[i]; j--)
    			{
    				for (k = 1; k <= number[i]; k++)//避免超过限制袋数
    					if (j >= k * cost[i])
    						dp[j] = max(dp[j], dp[j - k * cost[i]] + wight[i] * k);//背包公式
    				maxweight = max(maxweight, dp[j]);//找最大
    			}
    		}
    		cout << maxweight << endl;
    	}
        return 0;
    }
    
  • 相关阅读:
    初识redis
    支付宝退款操作
    《地质灾害防治这一年2013》读书摘要
    地质灾害防治工作的经验和体会
    关于地质灾害防治的一些认识
    应急信息报送和值班工作的培训学习
    《地质灾害防治这一年2012》读书摘要
    关于开源GIS和商业GIS的讨论
    B树索引学习
    cordova 开发 ios app 简要流程
  • 原文地址:https://www.cnblogs.com/gidear/p/10433304.html
Copyright © 2011-2022 走看看