日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Kattis - battleship【模拟】

發布時間:2023/12/16 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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【模拟】的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。