完美世界2020编程题-救雅典娜 & 英雄AB PK

				版权声明:本文为博主原创文章,转载请注明出处。					https://blog.csdn.net/u012319493/article/details/82154113				</div>
							<link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/ck_htmledit_views-f57960eb32.css">
							            <div id="content_views" class="markdown_views">
						<!-- flowchart 箭头图标 勿删 -->
						<svg xmlns="http://www.w3.org/2000/svg" style="display: none;"><path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path></svg>
						<p>救雅典娜 <br>

时间限制:C/C++语言 1000MS;其他语言 3000MS

内存限制:C/C++语言 65536KB;其他语言 589824KB

题目描述:

黄金圣斗士欧洛斯要去圣域救雅典娜,需要从左上角出发,每次只能向右或向下走,最后达到右下角见到雅典娜。地图每个位置的值代表圣斗士要遭遇的事情,如果是负数,说明此处有阻击,要让圣斗士损失血量,如果是非负数,代表此处有血瓶,能让圣斗士回血,圣斗士从左上角走到右下角的过程中,走到任何一个位置时,血量都不能少于1,为了保证圣斗士能救出雅典娜,初始血量至少是多少?地图为一个二维数组map,如下矩阵。根据map,返回初始血量。

这里写图片描述

输入
一个n*m的二维数组

第一行:数组的行数n(n>0)

第二行:数组的列数m(m>0)

第三行:数组,每个位置的血量,行优先

输出
对于每个测试实例,要求输出初始血量

样例输入
3
3
-2 -3 3 -5 10 1 0 30 -5
样例输出
6

#include <vector>
#include <iostream>
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;

    vector< vector<int> > v(n, vector<int>(m));
    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
            cin >> v[i][j];
    vector< vector<int> > dp(n, vector<int>(m));
    dp[--n][--m] = v[n][m] > 0 ? 1 : -v[n][m] + 1;
    for(int j=m-1; j>=0; j--)
        dp[n][j] = max(dp[n][j+1] - v[n][j], 1);
    for(int i=n-1; i>=0; i--)
    {
        dp[i][m] = max(dp[i+1][m] - v[i][m], 1);
        for(int j=m-1; j>=0; j--)
        {
            int right = max(dp[i][j+1] - v[i][j], 1);
            int down = max(dp[i+1][j] - v[i][j], 1);
            dp[i][j] = min(right, down);
        }
    }
    cout << dp[0][0];
}
  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

英雄PK
时间限制:C/C++语言 1000MS;其他语言 3000MS
内存限制:C/C++语言 65536KB;其他语言 589824KB
题目描述:
AB两队进行PK,每队有n个英雄,每局一个英雄出战进行PK,(且每个英雄只能出战一次),每个英雄都有武力值,武力值大的英雄获胜,武力值相同平局,平局没有得失,每赢一局该队获得100个元宝,输一局损失100个元宝。求A队最多可以赢多少元宝。

输入
第一行:一个正整数n(0

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int result = -1000;
void swap(int &a, int &b)
{
    int temp = a;
    a = b;
    b = temp;
}

void dfs(vector<int> &a, const vector<int> &b, int n, int dep, int ans)
{
    if(dep >= n)
    {
        if(ans > result)
            result = ans;
        return;
    }
    for(int i=dep; i<n; i++)
    {
            swap(a[dep], a[i]);

            int temp = 0;
            if(a[dep] > b[dep])
                temp = 100;
            else if(a[dep] < b[dep])
                temp = -100;
            dfs(a, b, n, dep+1, ans + temp);

            swap(a[dep], a[i]);
    }
}

int main()
{
    int n;
    cin >> n;

    vector<int> a(n), b(n);
    for(int i=0; i<n; i++)
        cin >> a[i];
    for(int i=0; i<n; i++)
        cin >> b[i];

    dfs(a, b, n, 0, 0);

    cout << result;
}
  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
					<link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-258a4616f7.css" rel="stylesheet">
                  </div>
				版权声明:本文为博主原创文章,转载请注明出处。					https://blog.csdn.net/u012319493/article/details/82154113				</div>
							<link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/ck_htmledit_views-f57960eb32.css">
							            <div id="content_views" class="markdown_views">
						<!-- flowchart 箭头图标 勿删 -->
						<svg xmlns="http://www.w3.org/2000/svg" style="display: none;"><path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path></svg>
						<p>救雅典娜 <br>

猜你喜欢

转载自blog.csdn.net/stay_foolish12/article/details/89065641