生活随笔
收集整理的這篇文章主要介紹了
完美世界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>
總結
以上是生活随笔為你收集整理的完美世界2020编程题-救雅典娜 英雄AB PK的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。