Codeforces 1397A - Juggling Letters(水題)

題目大意:

給你 x 組字串,試問能不能把這些字串進行重組後,能夠再重新分成 x 組字串,但字串內容則是全部一樣,可以輸出 YES,不行輸出 NO。

分析:

水題,這題真的水題,還是有點巧思的水題。喜歡這種水題

由於他會給你一些字串,但這些字串的字母可以全部移動,而他詢問說要讓重組後的字串全部一樣,於是只要確認每個字母除以 x 剛好是整除時就可以輸出 YES,如果不行就輸出 NO。

心得:

這題其實不難,但我在閱讀時也花了許多時間。以及我在思考題目時其實也不太能夠馬上很直觀了解,但進行假設與觀察後即可發現規律,我認為這題放在第一題是很不賴的設計。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <bits/stdc++.h>
#define LOCAL
using namespace std;

map<char , int> dict ;
string strTemp ;
int t , n ;

void ans(){
for(auto it : dict){
//cout << it.second << '\n' ;
if(it.second % n){
cout << "NO" << '\n' ;
return ;
}
}
cout << "YES" << '\n' ;
}

int main()
{

//#ifdef LOCAL
// freopen("in1.txt" , "r" , stdin );
//#endif // LOCAL

cin >> t ;
while(t--){
cin >> n ;
dict.clear();
for(int i = 0 ; i < n ; i++){
cin >> strTemp ;
for(int j = 0 ; j < strTemp.length() ; j++){
dict[strTemp[j]] +=1 ;
}
}
ans();
}
return 0;
}
  • 版權聲明: 本部落格所有文章除有特別聲明外,均採用 Apache License 2.0 許可協議。轉載請註明出處!
  • © 2020-2024 John Doe
  • Powered by Hexo Theme Ayer
  • PV: UV: