第17届BIT校园编程竞赛-现场赛(The 17-th BIT Campus Programming Contest - Onsite Round)

题目链接仪表板 - 第 17 届 BIT 校园编程竞赛 - 现场回合 - Codeforces --- Dashboard - The 17-th BIT Campus Programming Contest - Onsite Round - Codeforces

G-小p玩钢4

考虑两对相邻的有敌人的格子,可以发现无论先攻击哪一个都会多消耗 个单位的装备。所以最后的花 费和进攻顺序是没有关系的。 因此答案就是敌人总数量加上有多少对敌人是相邻的。

代码如下


#include
#include
#include
using namespace std;
int st[1005][1005],m,n,sum=0,cnt=0;
int main()
{
	cin>>m>>n;
	for(int i=1;i<=m;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cin>>st[i][j];
		}
	}
	for(int k=5;k>=1;k--)
	{
		for(int i=1;i<=m;i++)
		{
			for(int j=1;j<=n;j++)
			{
				cnt=0;
				if(st[i][j]==1)
				cnt=st[i][j]&

你可能感兴趣的:(算法,c++,数据结构)