@Alpacadh
2019-02-14T14:04:01.000000Z
字数 2369
阅读 792
Vova在玩RPG类型的游戏时遇到一个BOSS,每回合开始(他先手)他有两种选择:
、攻击BOSS(他自己的攻击力为1);
、吃药恢复自己1那么多的血,(1大于2且恢复后可能大于自身本来的1的初始血量);
BOSS有2 的血和2的攻击力,要求你以最快速度打败怪兽,然后输出需要的回合数和每回合的指令(HEAL为吃药恢复,STRIKE为攻击BOSS)
#include<bits/stdc++.h>
//#include<iostream>
//#include<algorithm>
//#include<cmath>
//#include<cstring>
//#include<stdio.h>
using namespace std;
const int inf=0x3f3f3f3f;
const int N=1e5+5;
const double eps=1e-4;
typedef long long ll;
typedef pair<int,ll> pil;
int a[N];
int main()
{
int h1,a1,c1,a2,h2;
scanf("%d%d%d",&h1,&a1,&c1);
int ma=h1;
scanf("%d%d",&h2,&a2);
int len=0;
for(int i=0;;i++)
{
if(h2<=0)
{
len=i;
break;
}
if(h1-a2<=0)
{
if(h2-a1<=0)
{
len=i+1;
a[i]=0;
break;
}
a[i]=1;
h1+=c1;
// cout<<h1<<endl;
h1-=a2;
}
else
{
h2-=a1;
h1-=a2;
a[i]=0;
}
}
printf("%d\n",len);
for(int i=0;i<len;i++)
{
if(a[i]==1)
printf("HEAL\n");
else
printf("STRIKE\n");
}
return 0;
}
#include<bits/stdc++.h>
//#include<iostream>
//#include<algorithm>
//#include<cmath>
//#include<cstring>
//#include<stdio.h>
using namespace std;
const int inf=0x3f3f3f3f;
const int N=1e5+5;
const double eps=1e-4;
typedef long long ll;
typedef pair<int,ll> pil;
char a[N];
int main()
{
int n;
int l=0,r=0,u=0,d=0;
scanf("%d%s",&n,a);
for(int i=0;i<n;i++)
{
if(a[i]=='L')
l++;
else if(a[i]=='R')
r++;
else if(a[i]=='U')
u++;
else
d++;
}
int ans=2*(min(l,r)+min(u,d));
printf("%d\n",ans);
return 0;
}
#include<bits/stdc++.h>
//#include<iostream>
//#include<algorithm>
//#include<cmath>
//#include<cstring>
//#include<stdio.h>
using namespace std;
const int inf=0x3f3f3f3f;
const int N=1e5+5;
const double eps=1e-4;
typedef long long ll;
typedef pair<int,ll> pil;
int a[N];
ll b[N];
int vis[N];
void dfs(int n,ll &ans)
{
ans++;
if(vis[a[n]]==0)
{
vis[a[n]]=1;
dfs(a[n],ans);
}
return;
}
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
int k=0;
for(int i=1;i<=n;i++)
{
if(vis[i]==0)
{
vis[i]=1;
dfs(i,b[++k]);
}
}
sort(b+1,b+1+k);
if(k==1)
printf("%lld\n",b[k]*b[k]);
else
{
b[k-1]+=b[k];
k--;
ll ans=0;
for(int i=1;i<=k;i++)
{
ans+=b[i]*b[i];
}
printf("%lld\n",ans);
}
return 0;
}