愚人節限定腦洞比賽 真就人均福爾摩斯唄 : )
A. Is it rated?
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Solution
注意首字母大寫,對應標題。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> p;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
template<typename T = int>
inline const T read()
{
T x = 0, f = 1; char ch = getchar();
while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + ch - '0'; ch = getchar(); }
return x * f;
}
template<typename T>
inline void write(T x)
{
if (x < 0) { putchar('-'); x = -x; }
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
int main()
{
cout << "No" << endl;
return 0;
}
B. Limericks
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
There was once young lass called Mary,
Whose jokes were occasionally scary.
On this April's Fool
Fixed limerick rules
Allowed her to trip the unwary.
Can she fill all the lines
To work at all times?
On juggling the words
Right around two-thirds
She nearly ran out of rhymes.
Input
The input contains a single integer 𝑎a (4≤𝑎≤9984≤a≤998). Not every integer in the range is a valid input for the problem; you are guaranteed that the input will be a valid integer.
Output
Output a single number.
Examples
input
Copy
35
output
Copy
57
input
Copy
57
output
Copy
319
input
Copy
391
output
Copy
1723
Solution
觀察樣例發現要求是輸出第一個因數和原數與它的商。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> p;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
template<typename T = int>
inline const T read()
{
T x = 0, f = 1; char ch = getchar();
while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + ch - '0'; ch = getchar(); }
return x * f;
}
template<typename T>
inline void write(T x)
{
if (x < 0) { putchar('-'); x = -x; }
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
int main()
{
int n = read();
for (int i = 2; i * i <= n; i++)
{
if (n % i == 0)
{
cout << i << n / i << endl;
break;
}
}
return 0;
}
C. ...And after happily lived ever they
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Input
The input contains a single integer 𝑎a (0≤𝑎≤630≤a≤63).
Output
Output a single number.
Examples
input
Copy
2
output
Copy
2
input
Copy
5
output
Copy
24
input
Copy
35
output
Copy
50
Solution
所有題目標題屬它最長,肯定暗含玄機! /滑稽
題目強調範圍是 0 - 63 ,64 = 2 ^ 64 ,而標題剛好是 6 個單詞。
再認真觀察發現標題語序是錯亂的,正確的順序是 And they lived happily ever after。
答案呼之欲出了:二進制重排
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> p;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
template<typename T = int>
inline const T read()
{
T x = 0, f = 1; char ch = getchar();
while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + ch - '0'; ch = getchar(); }
return x * f;
}
template<typename T>
inline void write(T x)
{
if (x < 0) { putchar('-'); x = -x; }
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
void trans(vector<int>& v)
{
swap(v[0], v[4]);
swap(v[2], v[3]);
}
int main()
{
int n = read();
vector<int> v;
for (int i = 0; i < 6; i++)
{
v.push_back(n & 1);
n >>= 1;
}
trans(v);
int res = 0;
for (int i = 0; i < 6; i++)
res += pow(2, i) * v[i];
write(res);
return 0;
}
D. Again?
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Input
The only line of the input contains a 7-digit hexadecimal number. The first "digit" of the number is letter A, the rest of the "digits" are decimal digits 0-9.
Output
Output a single integer.
Examples
input
Copy
A278832
output
Copy
0
input
Copy
A089956
output
Copy
0
input
Copy
A089957
output
Copy
1
input
Copy
A144045
output
Copy
1
Solution
這題沒什麼意思,強調了首尾字符範圍,只需判斷末位奇偶。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> p;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
template<typename T = int>
inline const T read()
{
T x = 0, f = 1; char ch = getchar();
while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + ch - '0'; ch = getchar(); }
return x * f;
}
template<typename T>
inline void write(T x)
{
if (x < 0) { putchar('-'); x = -x; }
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
int main()
{
string s;
cin >> s;
cout << ((s[s.length() - 1] - '0') & 1) << endl;
return 0;
}
E. Jordan Smiley
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Input
The input contains two integers 𝑟𝑜𝑤row, 𝑐𝑜𝑙col (0≤𝑟𝑜𝑤,𝑐𝑜𝑙≤630≤row,col≤63), separated by a single space.
Output
Output "IN" or "OUT".
Examples
input
Copy
0 0
output
Copy
OUT
input
Copy
27 0
output
Copy
IN
input
Copy
0 27
output
Copy
OUT
input
Copy
27 27
output
Copy
IN
Solution
詢問一個座標是否在迷宮內部,沒點技術真的搞不定這題 233
一種快捷做法是把這張圖保存下來,用圖片處理軟件進行上色,再用 Python 識別打表。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> p;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
template<typename T = int>
inline const T read()
{
T x = 0, f = 1; char ch = getchar();
while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + ch - '0'; ch = getchar(); }
return x * f;
}
template<typename T>
inline void write(T x)
{
if (x < 0) { putchar('-'); x = -x; }
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
vector<string> s = {
" # # ###### # ",
" # ### # # # # ##### ",
" ### # # ## # # # ",
" #### # # ##### #### # ### # ",
" ## # # #### # # # ## ",
" # ## ##### ### ### # # ## # # # ",
" ### # # # # #### ## ## ## ## ",
" ###### ## ## ### ### ### ## # # ### ",
" ############ # # # ## ## ## # ### ",
" #################### ####### #### ########## ",
" ################################################ ",
" ################################################## ",
" ################################################## ",
" #################################################### ",
" ###################################################### ",
" ###################################################### ",
" ######################################################## ",
" ########################################################## ",
" ######################################################## ",
" ############ # ############## # # ############# ",
" ## ######### # ############### # ######## ",
" #### ##### ## # ############### ## ## # ## ## ",
" ####### # ### ### ########### # # ## ###### ",
" ######### # # ## ## ######### ## ##### # ######### ",
" ############ ## ### ### ####### # # ### ########### ",
" ######### # ### ### ######## # ##### # # # ######## ",
"############ ### # # # # ###### # # ## ### #########",
"########### # # ## ### ### #### # ### #### ### # #########",
"########### ###### #### # # # # # # #### ### #########",
"########### # # ### ### # # ## ## # # # # #########",
"############ ## #### ## ### # ### #### # ###### ##########",
"########### ### # # ### # ### #### # ### # #########",
"############# ## ### ## ### ## # ## ## # # #########",
"############## ## # # # # # # # ## # ## ## ############",
"############ #### # # # # #### ## # # ### ### ###########",
"############# # # ### #### # ## # ## #############",
"################ ### # ## ## ## ## # ### # # ############",
"################## # ###### ####### # ################",
" ################ # ##### # ########### # ############## ",
" ############################## ############################ ",
" ########################### # # ############################# ",
" ######################### # ################################ ",
" ######################## # ############################# ",
" ####### ################### ############################### ",
" ####### # ################ ##################### ####### ",
" ####### # ########### # ########### ##### # ###### ",
" ####### # # # # # ## # ## # # # ## ## # ####### ",
" ######## ## # ## ## # # ### ######## ",
" ####### # #### #### ### ### ### ##### # ######### ",
" ########## # # # # #### ### ## # # ######### ",
" ######## ## ## # # # # ### # ########## ",
" ######### ## ##### ## # # # ## ############# ",
" ######### ### # # ### # ### # ########### ",
" ######### #### ### ## #### #### ############ ",
" ######### ## # # # # ############## ",
" ############ # #### ## ## # ## ############ ",
" ############# #### # ############ ",
" #################### ################# ",
" #################################### ",
" ################################ ",
" ############################## ",
" ######################## ",
" #################### ",
" ############ " };
int main()
{
int x, y;
cin >> x >> y;
cout << (s[x][y] == '#' ? "IN" : "OUT") << endl;
return 0;
}
F. Elementary!
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Input
The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive.
Output
Output "YES" or "NO".
Examples
input
Copy
GENIUS
output
Copy
YES
input
Copy
DOCTOR
output
Copy
NO
input
Copy
IRENE
output
Copy
YES
input
Copy
MARY
output
Copy
NO
input
Copy
SMARTPHONE
output
Copy
NO
input
Copy
REVOLVER
output
Copy
YES
input
Copy
HOLMES
output
Copy
NO
input
Copy
WATSON
output
Copy
YES
Solution
個人認爲這題最有意思。
初看樣例一頭霧水,這些都是基本演繹法裏的人名和關鍵詞。
再看標題總覺得在暗示什麼:Elementary 不僅是《基本演繹法》,也是【元素】的形容詞。
福爾摩斯作品中不乏查表破案的情節,再看樣例發現 GENIUS == GE + N + I + U + S
也許只有化競生能一眼看穿吧 /滄桑
先把 118 個元素符號打表,然後 DFS。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> p;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
template<typename T = int>
inline const T read()
{
T x = 0, f = 1; char ch = getchar();
while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + ch - '0'; ch = getchar(); }
return x * f;
}
template<typename T>
inline void write(T x)
{
if (x < 0) { putchar('-'); x = -x; }
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
vector<string> v = { "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr", "Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn", "Sb", "Te", "I", "Xe", "Cs", "Ba", "La", "Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt", "Au", "Hg", "Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr", "Ra", "Ac", "Th", "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm", "Md", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds", "Rg", "Cn", "Nh", "Fl", "Mc", "Lv", "Ts", "Og" };
string toupper(const string& s)
{
string res = s;
for (int i = 0; i < res.length(); i++)
res[i] = toupper(res[i]);
return res;
}
bool find(const string& s)
{
for (auto it : v) if (s == toupper(it)) return true;
return false;
}
bool dfs(int pos, const string& s)
{
if (pos == s.length()) return true;
for (int i = pos; i < s.length(); i++)
if (find(s.substr(pos, i - pos + 1)) && dfs(i + 1, s))
return true;
return false;
}
int main()
{
string s;
cin >> s;
cout << (dfs(0, s) ? "YES" : "NO") << endl;
return 0;
}
後面兩題更讓人禿頂,聽說要現學一種編程語言。。。
人家 tourist 一小時就 AK 了,差距啊!!!