Kattis - battleship【模拟】
生活随笔
收集整理的這篇文章主要介紹了
Kattis - battleship【模拟】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目鏈接: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; }總結
以上是生活随笔為你收集整理的Kattis - battleship【模拟】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Mps317 arduino
- 下一篇: msf编码免杀