if (rand() % 20)
continue;
npcHp -= pokemonAttack;
if (npcHp <= 0)
return 0;
}
}
int main() {
srand((unsigned) time(NULL));
int hp, attack;
int res = 0;
scanf(“%d %d”, &hp, &attack);
for (int i = 0; i < MAX; ++i)
res += game(hp, attack);
printf(“%.2lf”, res * 1.0 / MAX);
return 0;
}
#include
#include
using namespace std;
int mat[100][100];
bool vis[100][100];
struct node {
int x, y, dis;
node() = default;
node(int x, int y, int dis) : x(x), y(y), dis(dis) {}
};
void bfs()
{
bool visS = false;
node beg = node(1, 1, 0);
queue que;
que.push(beg);
vis[beg.x][beg.y] = true;
while (!que.empty()) {
node now = que.front();
que.pop();
if (now.x + 1 >= 1 && now.x + 1 <= 10 && now.y >= 1 && now.y <= 10
&& !vis[now.x + 1][now.y] && mat[now.x + 1][now.y] != 1) {
if (mat[now.x + 1][now.y] == 2)
visS = true;
if (mat[now.x + 1][now.y] == 3) {
if (visS)
cout << "S ";
else
cout << "R ";
cout << now.dis + 1;
}
que.push(node(now.x + 1, now.y, now.dis + 1));
vis[now.x + 1][now.y] = true;
}
if (now.x - 1 >= 1 && now.x - 1 <= 10 && now.y >= 1 && now.y <= 10
&& !vis[now.x - 1][now.y] && mat[now.x - 1][now.y] != 1) {
if (mat[now.x - 1][now.y] == 2)
visS = true;
if (mat[now.x - 1][now.y] == 3) {
if (visS)
cout << "S ";
else
cout << "R ";
cout << now.dis + 1;
}
que.push(node(now.x - 1, now.y, now.dis + 1));
vis[now.x - 1][now.y] = true;
}
if (now.x >= 1 && now.x <= 10 && now.y + 1 >= 1 && now.y + 1 <= 10
&& !vis[now.x][now.y + 1] && mat[now.x][now.y + 1] != 1) {
if (mat[now.x][now.y + 1] == 2)
visS = true;
if (mat[now.x][now.y + 1] == 3) {
if (visS)
cout << "S ";
else
cout << "R ";
cout << now.dis + 1;
}
que.push(node(now.x, now.y + 1, now.dis + 1));
vis[now.x][now.y + 1] = true;
}
if (now.x >= 1 && now.x <= 10 && now.y - 1 >= 1 && now.y - 1 <= 10
&& !vis[now.x][now.y - 1] && mat[now.x][now.y - 1] != 1) {
if (mat[now.x][now.y - 1] == 2)
visS = true;
if (mat[now.x][now.y - 1] == 3) {
if (visS)
cout << "S ";
else
cout << "R ";
cout << now.dis + 1;
}
que.push(node(now.x, now.y - 1, now.dis + 1));
vis[now.x][now.y - 1] = true;
}
}
}
int main()
{
int n = 10;
char ch;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> ch;
if (ch == ‘X’)
mat[i][j] = 1;
else if (ch == ‘S’)
mat[i][j] = 2;
else if (ch == ‘R’)
mat[i][j] = 3;
}
cin.ignore();
}
bfs();
return 0;
}
#include
#include
using namespace std;
vector<vector> map;
int n, m, ans = 0;
void dfs(int r, int c) {
if (r < 0 || r >= n || c < 0 || c >= m || map[r][c] == 0) return;
map[r][c] = 0;
int di[4] = {0, 0, 1, -1};
int dj[4] = {1, -1, 0, 0};
for (int i = 0; i < 4; i++)
dfs(r + di[i], c + dj[i]);
}
int main() {
cin >> n >> m;
map = vector<vector>(n, vector(m));
for (int i = 0; i < n; i++)
for (int j = 0; j < m; ++j)
cin >> map[i][j];
for (int r = 0; r < n; ++r)
for (int c = 0; c < m; ++c)
if (map[r][c] != 0) {
++ans;
dfs(r, c);
}
cout << ans;
return 0;
}
#include
#include
using namespace std;
int x;
int arr[100], b[100];
int sum;
int main()
{
cin >> x;
for (int i = 1; i <= 7; i++)
cin >> arr[i];
//计算在不释放技能的前提下拥有多少奖励
for (int i = 1; i <= 7; i++) {
cin >> b[i];
if (b[i])
sum += arr[i];
}
//以下计算释放技能产生的收益
int maxx = 0;
for (int i = 1; i <= 7 - x + 1; i++) {
int tmp = 0;
for (int j = i; j < i + x; j++)
if (!b[j])
tmp += arr[j];
if (tmp > maxx)
maxx = tmp;
}
cout << sum + maxx;
return 0;
}
#include
#include
#include
#define N 10000
using namespace std;
string sub, str;
int dp[N][N];
int main()
{
cin >> str >> sub;
if (sub[0] == str[0])
dp[0][0] = 1;
for (int j = 1; j < str.length(); j++)
if (sub[0] == str[j])
dp[0][j] = dp[0][j - 1] + 1;
else
dp[0][j] = dp[0][j - 1];
for (int i = 1; i < sub.length(); i++)
for (int j = 1; j < str.length(); j++) {
if (sub[i] == str[j])
dp[i][j] = dp[i - 1][j - 1] + dp[i][j - 1];
else
dp[i][j] = dp[i][j - 1];
}
cout << dp[sub.length() - 1][str.length() - 1];
return 0;
}
#include
#include
#define rep(i, a, b) for(long long i=a;i<=b;i++)
using namespace std;
typedef long long ll;
ll n, m, s, t, dif[300050];
ll get(ll x)
{
if (x > 0) return -x * s;
else return -x * t;
}
int main()
{
scanf(“%lld %lld% lld% lld”, &n, &m, &s, &t);
ll v, w = 0, ans = 0;
rep(i, 0, n) {
scanf(“%lld”, &v);
if (i != 0) {
dif[i - 1] = v - w;
ans += get(dif[i - 1]);
}
w = v;
}
rep(i, 1, m) {
ll a, b, c;
scanf(“%lld%lld%lld”, &a, &b, &c);
ans -= get(dif[a - 1]);
dif[a - 1] += c;
ans += get(dif[a - 1]);
if (b != n) {
ans -= get(dif[b]);
dif[b] -= c;
ans += get(dif[b]);
}
printf(“%lld\n”, ans);
}
return 0;
}
#include
#include
using namespace std;
int t;
int dp[1000000];
int n = 100000;
int main()
{
for (int i = 1; i <= n; i++)
dp[i] = 0x7fffffff; //0x7fffffff等价INT_MAX
dp[1] = 1;
小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Java工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新Java开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Java)
最后
各位读者,由于本篇幅度过长,为了避免影响阅读体验,下面我就大概概括了整理了
技术停滞不前!**
因此收集整理了一份《2024年最新Java开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
[外链图片转存中…(img-INYe52OB-1710955618471)]
[外链图片转存中…(img-cv6qqjfE-1710955618471)]
[外链图片转存中…(img-cSx0ScvT-1710955618471)]
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Java)
[外链图片转存中…(img-5A4cCM2g-1710955618472)]
最后
各位读者,由于本篇幅度过长,为了避免影响阅读体验,下面我就大概概括了整理了
[外链图片转存中…(img-oKRTI6HK-1710955618472)]
[外链图片转存中…(img-fWuTyWsq-1710955618472)]
[外链图片转存中…(img-Xcq8H1bl-1710955618473)]
[外链图片转存中…(img-tOZaONP7-1710955618473)]