Kattis

来源:互联网 发布:淘宝限时折扣 编辑:程序博客网 时间:2024/05/22 03:04

这里写图片描述
这里写图片描述
这里写图片描述

题目链接:Kattis-battleship

题目大意:这道题目意思真的好坑。。

两个军队作战,互相射击对方的船,输入m,n,k,然后分别输入两个军队的地图。#表示该坐标上为船,_表示该坐标上为水。(两幅地图不相关)

给出k个射击坐标,

A先开始射击:如果A射击到B船,则继续射击。直到子弹用完 or B方无船 or A射击到水面-->则换B射击

注意: B方无船,A停止射击。

为了公平,A,B的回合次数一样,由于A先开始射击,也就是说:A射击时如果B无船了。B还能继续射击一回合而不是直接终止

==>即:把A射击x回合 + B射击y回合 当作一轮。 一轮结束后再进行结算

结算:if (ship_a == 0 || ship_b == 0) break;

另外: m 和 n 需注意不要反了

以下是代码:

#include <iostream>#include <iomanip>#include <fstream>#include <sstream>#include <cmath>#include <cstdio>#include <cstring>#include <cctype>#include <algorithm>#include <functional>#include <numeric>#include <string>#include <set>#include <map>#include <stack>#include <vector>#include <queue>#include <deque>#include <list>using namespace std;string a[50];string b[50];int x[2005];int y[2005];int main(){    int _;    cin >> _;    while(_--)    {        int n,m,t;        cin >> m >> n >> t;        for (int i = 0; i < n; i++) cin >> a[i];        for (int i = 0; i < n; i++) cin >> b[i];        int ship_a = 0, ship_b = 0;        for (int i = 0; i < n; i++)        {            for (int j = 0; j < m; j++)            {                if (a[i][j] == '#') ship_a++;            }        }        for (int i = 0; i < n; i++)        {            for (int j = 0; j < m; j++)            {                if (b[i][j] == '#') ship_b++;            }        }        int ans = 0;        for (int i = 0; i < t; i++)        {            cin >> x[i] >> y[i];        }        for (int i = 0; i < t;)        {            //  cout << "1." << x[i] << " " << y[i] << " " << b[n - y[i] - 1][x[i]] << endl;            //1.            if (b[n - y[i] - 1][x[i]] == '#' && i < t)            {                while(b[n - y[i] - 1][x[i]] == '#' && i < t)                {                    b[n - y[i] - 1][x[i]] = '_';                    ship_b--;                    if (ship_b == 0) break;                    i++;                }                i++;            }            else i++;            //  cout << "2." << x[i] << " " << y[i] << " " << a[n - y[i] - 1][x[i]] << endl;            //2.            if (a[n - y[i] - 1][x[i]] == '#' && i < t)            {                while(a[n - y[i] - 1][x[i]] == '#' && i < t)                {                    a[n - y[i] - 1][x[i]] = '_';                    ship_a--;                    if (ship_a == 0) break;                    i++;                }                i++;            }            else i++;            if (ship_a == 0 || ship_b == 0) break;        }        if (ship_a ==  ship_b || (ship_a > 0 && ship_b > 0)) cout << "draw\n";        else if (ship_a) cout << "player one wins\n";        else cout << "player two wins\n";    }    return 0;}
0 0
原创粉丝点击