題目連接:https://ac.nowcoder.com/acm/contest/1085#questionios
A:c++
題意:一個數軸,再給定m個區間,問沒被區間覆蓋的最大連續區間是多大數組
idea:按左端點爲第一關鍵字排序,而後區間合併,從左到右再遍歷一遍便可ide
1 void
B:idea
題意:詢問每一個點周圍有多少炸彈spa
idea:暴力遍歷3d
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 int n, m, cnt[1010][1010]; 5 char a[1010][1010]; 6 7 int main() 8 { 9 cin >> n >> m; 10 for (int i = 0; i < n; i ++ ) 11 for (int j = 0; j < m; j ++ ) 12 cin >> a[i][j]; 13 14 for (int i = 0; i < n; i ++ ) 15 { 16 for (int j = 0; j < m; j ++ ) 17 { 18 int ans = 0; 19 if (a[i][j] == '.') 20 { 21 if (a[i - 1][j] == '*') ans ++ ; 22 if (a[i - 1][j - 1] == '*') ans ++ ; 23 if (a[i - 1][j + 1] == '*') ans ++ ; 24 if (a[i][j - 1] == '*') ans ++ ; 25 if (a[i][j + 1] == '*') ans ++ ; 26 if (a[i + 1][j + 1] == '*') ans ++ ; 27 if (a[i + 1][j - 1] == '*') ans ++ ; 28 if (a[i + 1][j] == '*') ans ++ ; 29 } 30 cnt[i][j] = ans; 31 } 32 } 33 34 for (int i = 0; i < n; i ++ ) 35 { 36 for (int j = 0; j < m; j ++ ) 37 { 38 if (a[i][j] == '*') cout << "*"; 39 else cout << cnt[i][j]; 40 } 41 cout << endl; 42 } 43 return 0; 44 }
C:code
題意:給出一個數組,計算出現次數爲奇數次的數的異或和blog
idea:根據異或和的性質,把全部數所有異或計算便可排序
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 5 using namespace std; 6 int n; 7 8 int main() 9 { 10 scanf("%d",&n); 11 int ans = 0; 12 for (int i = 0; i < n; i ++ ) 13 { 14 int x; 15 scanf("%d",&x); 16 ans ^= x; 17 } 18 printf("%d",ans); 19 return 0; 20 }
D:
題意:解密,給出一段密文,輸出解密後的字符串
idea:C≡k1∗x+k2(mod 26),由於總共就26個字母,因此能夠先打表,預處理出來每一個密文對應的明文
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 int cnt[30]; 5 6 int main() 7 { 8 int k1, k2; 9 cin >> k1 >> k2; 10 for (int i = 0; i <26; i ++ ) 11 { 12 for (int j = 0; j < 26; j ++ ) 13 { 14 if ((k1 * j + k2) % 26 == i) 15 { 16 cnt[i] = j; 17 break; 18 } 19 } 20 } 21 string s; 22 cin >> s; 23 int len = s.size(); 24 for (int i = 0; i < len; i ++ ) 25 { 26 if (s[i] >= 'a' && s[i] <= 'z') 27 { 28 int c = s[i] - 'a'; 29 printf("%c",cnt[c] + 'a'); 30 } 31 else 32 { 33 int c = s[i] - 'A'; 34 printf("%c",cnt[c] + 'A'); 35 } 36 } 37 return 0; 38 }
I:
題意:電梯上升一層須要一秒,問到你這層至少須要多少秒
idea:簽到,直接算就行
1 #include <iostream> 2 #include <cstdio> 3 4 using namespace std; 5 const int MAXN = 1e6 + 10; 6 int n, k, a[MAXN]; 7 8 int main() 9 { 10 cin >> n >> k; 11 for (int i = 0; i < n; i ++ ) scanf("%d",&a[i]); 12 13 int ans = 0; 14 for (int i = 0; i < n; i ++ ) 15 { 16 if (a[i] > k && a[i] > ans) ans = a[i]; 17 } 18 ans = (ans - k) * 2 + k - 1; 19 cout << ans << endl; 20 return 0; 21 }
PS:四題半,挺糟糕的,下次必定要五題,就這樣。