Try   HackMD

TJPC 11th 基礎班比賽題解

PA - Hello Ezy!

把題目看完 通靈一下 就知道blame雖然會騙人,但blame就是blame
所以正確的問候語都是He1Io Blame!
只拿到1分的就是用Blame騙EZY的錯誤名字問候Blame

AC code
#include<bits/stdc++.h> using namespace std; int main(){ cout << "He1Io Blame!" << '\n'; }

PB - 圖書館

稍微閱讀一下就知道
該字串的長度為奇數:一個字出現奇數次+剩下的字都出現偶數次
該字串的長度為偶數:全部的字都出現偶數次

把字母出現次數記錄在一個陣列裡,用for迴圈掃過一看有幾個字母出現奇數次
如果超過1個就不可能是回文

92%:
第7行用cin
100%:
第7行用getline,第16行判斷空格的數量

稍微實作一下就可以AC了

AC code
#include<bits/stdc++.h> using namespace std; int main(){ string a; int c = 0; int b[128] = {0}; getline(cin , a); for( int i = 0 ; i < (int)a.size() ; i++ ){ b[(int)a[i]]++; } for( int i = 0 ; i < 26 ; i++ ){ if( (b['a'+i]+b['A'+i]) % 2 ){ c++; } } if( b[' '] % 2 ) c++; if( c > 1 ) cout << "NO" << '\n'; else cout << "YES" << '\n'; }

PC - 數字命運法

88%:
在n變成1之前
n是奇數要 * 3 + 1
n是偶數要 /2

100%:
假如有認真看題目就知道輸入的n是絕對值
n如果 <= 0 則不可能透過上述的方法變成1
所以n <= 0 時輸出-1

AC code
#include<bits/stdc++.h> using namespace std; int main(){ long long n; cin >> n; if( n <= 0 ) cout << -1 << '\n'; else{ cout << n; while( n != 1 ){ cout << " "; if( n%2 ) n = n*3+1; else n /= 2; cout << n; } } }

PD - 尋寶

題目大概意思:
給你一個n*m的地圖跟一串字串表示路線
問D是否能在不接觸 # 或掉出地圖的情況下照著路線移動至T
*且要在最後一步剛好到T,途中有經過但最後不是停在T上的話不算

開一個二維陣列儲存地圖,把題目要判斷的東西全部判斷過就可以AC了

AC code
#include<bits/stdc++.h> using namespace std; char a[5010][5010]; string mov = "LRUD"; int mx[] = {0 , 0 , -1 , 1 }; int my[] = { -1 , 1 , 0 , 0 }; int main(){ ios::sync_with_stdio(false),cin.tie(0); int n , m , x , y; string s; cin >> n >> m >> x >> y; x--; y--; for( int i = 0 ; i < n ; i++ ){ for( int j = 0 ; j < m ; j++ ){ cin >> a[i][j]; } } cin >> s; for( int i = 0 ; i < (int)s.size() ; i++ ){ if( s[i] == '!' ) break; for( int mo = 0 ; mo < 4 ; mo++ ){ if( s[i] == mov[mo] ){ if( x + mx[mo] >= 0 && x + mx[mo] < n && y + my[mo] >= 0 && y + my[mo] < m && a[x + mx[mo]][y + my[mo]] != '#' ){ x += mx[mo]; y += my[mo]; } else{ cout << "NO" << '\n'; return 0; } } } } if( a[x][y] == 'T' ) cout << "YES" << '\n'; else cout << "NO" << '\n'; }

PE - 冰菓

某一點僅能影響水平軸、垂直軸、斜線是否冰果
開一個二維陣列把Blame簽的數字存下來
再開一個布林值的二維陣列判斷該格的數字是否是電腦輸出的T個數字中的數字

因為能成立斜線冰果的斜線只有兩條,觀察一下就會發現b[x][y]中只有符合x=y或x+y=8-1的位置才會影響

所以在判斷的時候:
判斷垂直水平線中9個數字電腦是否都已經輸出
若該格符合x=y或x+y=9-1就再多判斷一下斜線的9+9格

AC code
#include<bits/stdc++.h> using namespace std; int bi[9][9] , t , a; bool bb[9][9] = {0}; int f( int y , int x ){ int vert = 0 , hori = 0 , basl = 0 , forsl = 0; //vertical horizontal backslash:\ forward slash:/ //上面是正式英文 變數不想打太長 for( int i = 0 ; i < 9 ; i++ ){ if( bb[i][x] == 1 ) vert ++; if( bb[y][i] == 1 ) hori ++; } if( x == y || x + y == 8 ){ for( int i = 0 ; i < 9 ; i++ ){ if( bb[i][i] == 1 ) basl ++; if( bb[i][8-i] == 1 ) forsl ++; } } if( vert == 9 || hori == 9 || basl == 9 || forsl == 9 ){ cout << "YES" << '\n'; return 1; } return 0; } int main(){ for( int i = 0 ; i < 9 ; i ++ ){ for( int j = 0 ; j < 9 ; j++ ){ cin >> bi[i][j]; } } cin >> t; for( int tt = 0 ; tt < t ; tt++ ){ cin >> a; for( int i = 0 ; i < 9 ; i ++ ){ for( int j = 0 ; j < 9 ; j++ ){ if( bi[i][j] == a ){ bb[i][j] = 1; if( f(i,j) ) return 0; } } } } cout << "NO" << '\n'; }