1. 程式人生 > >UVa 220 (implement)

UVa 220 (implement)

找到了一個小bug,就是輸出座標時,會重複輸出,後來加了getout控制就AC了。
寫模擬題思維一定要嚴謹,程式碼嚴謹已讀很重要

/*
* 20171109
*/

//#define LOCAL

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>

using namespace std;

int dx[] = {-1,-1,-1,0,1,1,1,0};
int dy[] = {-1,0,1,1,1,0,-1,-1};
char m[10][10];
char now[5
]; char nxt[5]; int main() { #ifdef LOCAL freopen("input.txt","r",stdin); freopen("ans.txt","w",stdout); #endif int n; scanf("%d",&n); for(int nn=0;nn<n;nn++) { if(nn!=0) printf("\n"); memset(m,0,sizeof(m)); for(int i=1;i<=8;i++) { char
mt[10]; scanf("%s",mt); for(int j=1;j<=8;j++) m[i][j] = mt[j-1]; } scanf("%s",now); if(now[0]=='W') sprintf(nxt,"B"); else nxt[0] = 'W'; char c[5]; while(scanf("%s",c)==1) { if(c[0]=='L') { bool
flag = false; for(int i=1;i<=8;i++) for(int j=1;j<=8;j++) if(m[i][j]=='-') { bool getout = true; for(int k=0;k<8&&getout;k++) if(m[i+dx[k]][j+dy[k]]==nxt[0]) { for(int p=1;;p++) { if(m[i+p*dx[k]][j+p*dy[k]]==0||m[i+p*dx[k]][j+p*dy[k]]=='-') break; if(m[i+p*dx[k]][j+p*dy[k]]==nxt[0]) continue; if(m[i+p*dx[k]][j+p*dy[k]]==now[0]) { if(flag) printf(" "); flag = true; printf("(%d,%d)",i,j); getout = false; break; } } } } if(!flag) printf("No legal move."); printf("\n"); } else if(c[0] == 'M') { bool flag = false; int i = c[1] - '0'; int j = c[2] - '0'; for(int k=0;k<8;k++) if(m[i+dx[k]][j+dy[k]]==nxt[0]) { for(int p=1;;p++) { if(m[i+p*dx[k]][j+p*dy[k]]==0||m[i+p*dx[k]][j+p*dy[k]]=='-') break; if(m[i+p*dx[k]][j+p*dy[k]]==nxt[0]) continue; if(m[i+p*dx[k]][j+p*dy[k]]==now[0]){ flag = true; break;} } } if(!flag) swap(now[0],nxt[0]); m[i][j] = now[0]; i = c[1] - '0'; j = c[2] - '0'; for(int k=0;k<8;k++) if(m[i+dx[k]][j+dy[k]]==nxt[0]) { for(int p=1;;p++) { if(m[i+p*dx[k]][j+p*dy[k]]==0||m[i+p*dx[k]][j+p*dy[k]]=='-') break; if(m[i+p*dx[k]][j+p*dy[k]]==nxt[0]) continue; if(m[i+p*dx[k]][j+p*dy[k]]==now[0]) { for(int t=p-1;t>=1;t--) m[i+t*dx[k]][j+t*dy[k]] = now[0]; break; } } } map<char,int> cnt; for(i=1;i<=8;i++) for(j=1;j<=8;j++) { if(m[i][j]=='W') cnt['W']++; else if(m[i][j]=='B') cnt['B']++; } printf("Black -%3d White -%3d\n",cnt['B'],cnt['W']); swap(now[0],nxt[0]); } else if(c[0] == 'Q') { for(int i=1;i<=8;i++) { for(int j=1;j<=8;j++) { printf("%c",m[i][j]); } printf("\n"); } break; } } } return 0; }

相關推薦

UVa 220 (implement)

找到了一個小bug,就是輸出座標時,會重複輸出,後來加了getout控制就AC了。 寫模擬題思維一定要嚴謹,程式碼嚴謹已讀很重要 /* * 20171109 */ //#define LOCAL #include <cstdio> #incl

UVA - 220 -Othello (模擬)

連結: https://vjudge.net/problem/UVA-220 題意: 見紫書96頁 思路: 見程式碼 #include <bits/stdc++.h> using namespace std; char mp[10][10]; int f[2]

Uva 220 Othello 黑白棋 (習題4-3)

做完這道加上前面兩道,這一章果然都是呼叫函式的。。。 自己寫一堆函式來搞 寫的過程中甚至覺得自己可以考慮寫一個黑白棋的遊戲了233 主要還是一個模擬 其實做了象棋那題的話會發現和象棋那題差不多,也是一堆函式堆出來的 象棋那題有一個思路就是需要對不同棋子也不同的函

uva 220 趣味黑白棋 精簡程式碼

#include<iostream>#include<cstdio>#include<string.h>using namespace std;char map[20][20];int row[2][8]={1,1,0,-1,-1,-1,0

uva 220 Othello

未A,但是測試了好多資料,沒有找出錯誤。#include<iostream> #include<cstdio> #include<cstring> using namespace std; using namespace std; cha

UVa 11149 矩陣的冪(矩陣倍增法模板題)

ble 化簡 .cn target ans txt put std net https://vjudge.net/problem/UVA-11149 題意: 輸入一個n×n矩陣A,計算A+A^2+A^3+...A^k的值。 思路: 矩陣倍增法。

UVA - 434 Matty&#39;s Blocks

mes [0 () block += tty scan 一個 ems 題意:給你正視和側視圖,求最多多少個,最少多少個 思路:貪心的思想。求最少的時候:由於能夠想象著移動,盡量讓兩個視圖的重疊。所以我們統計每一個視圖不同高度的個數。然後計算。至於的話。就是每次拿正視圖的

UVA 11997 K Smallest Sums 優先隊列 多路合並

algorithm span 大白 while logs truct %d 算法 省賽   vjudge 上題目鏈接:UVA 11997   題意很簡單,就是從 k 個數組(每個數組均包含 k 個正整數)中各取出一個整數相加(所以可以得到 kk 個結果),輸出前 k 小的和

UVA 567 Risk【floyd】

art printf ios org std span app process iostream 題目鏈接: option=com_onlinejudge&Itemid=8&page=show_problem&problem=5

uva 1585

cout clu cnblogs push uva i++ namespace cin str #include <bits/stdc++.h> using namespace std; int main() { int k; cin>&

UVA 1584 環狀序列

-- 開頭 給定 字典 字典序 clu cout con sca 題意: 給定一個環狀字符串,輸出字典序最小的線裝字符串。 分析: 我一開始是將原字符串*2去模擬環,然後分別截取以字符串不同字母為首的子串,然後用sort去排序輸出最小的串,復雜度為O(n^2 + nlogn

Marvelous Mazes UVA - 445

累加 == return include printf str string iostream log #include<iostream> #include<stdio.h> #include<string> #include<

紫書第五章訓練 uva 10763 Foreign Exchange by crq

evo pan hang n) 情況 sed 是否 for ear Your non-profit organization (iCORE - international Confederation of Revolver Enthusiasts) coordinates

UVA 10129 Play on Words

bool seq lis rest ble u+ contains con sync Some of the secret doors contain a very interesting word puzzle. The team of archaeologists ha

【組合計數】UVA - 11538 - Chess Queen

bre cpp name using blog ios log return algorithm 考慮把皇後放在同一橫排或者統一縱列,答案為nm(m-1)和nm(n-1),顯然。 考慮同一對角線的情況不妨設,n<=m,對角線從左到右依次為1,2,3,...,n-1,n

UVA 12563(Jin Ge Jin Qu hao)

case class 利用 i++ its 價值 con == 節省空間 開始認真學DP。我對滾動數組的理解是:後一個狀態可以由前一個狀態求得,便可以使用一維數組重復利用節省空間復雜度。 這個題要註意題目要求的前提,求次數可以看作重量為v[i]價值為1放入w-1的背包,歌曲

POJ 3294 UVA 11107 Life Forms 後綴數組

ise -c orm pac str lap sizeof true n-1 相同的題目,輸出格式有區別。 給定n個字符串,求最長的子串,使得它同時出現在一半以上的串中。 不熟悉後綴數組的童鞋建議先去看一看如何用後綴數組計算兩個字符串的最長公共子串 Ural1517 這道題

【Java】【滾動數組】【動態規劃】UVA - 11137 - Ingenuous Cubrency

得到 lose math scanner light clas details 狀態 ann 滾動數組優化自己畫一下就明白了。 http://blog.csdn.net/u014800748/article/details/45849217 解題思路:本題利用遞推關系解決。

UVa 10651 Pebble Solitaire(DP 記憶化搜索)

src output one row max -s turn -- nth Pebble Solitaire Pebble solitaire is an interesting game. This is a game where you are given

uva 10340 all in all

() ring ace while clu return include all urn #include<bits/stdc++.h> using namespace std; bool cmpare(string t,string s) { int