A. muh and sticks
Question: give you six sticks and ask if you can spell out a bear or elephant. To spell out a bear, you must first have four sticks with the same length as the leg, and the other two sticks with different lengths as the body and head. An elephant fight also requires four sticks of the same length as its legs, but two other sticks of the same length as its body and head. Solution: For details, see the code. Code:
1 #include <cstdio> 2 #include <cstring> 3 #include <set> 4 #include <algorithm> 5 using namespace std; 6 7 int m[11]; 8 9 int main() {10 int a;11 for(int i = 0; i < 6; i++) { scanf("%d", &a); m[a]++; }12 int f = 0;13 for(int i = 1; i <= 9; i++) { if(m[i] >= 4) m[i] -= 4, f = 1; }14 if(!f) { printf("Alien\n"); return 0; }15 for(int i = 1; i <= 9; i++) { if(m[i] >= 2) f = 0; }16 if(!f) printf("Elephant\n");17 else printf("Bear\n");18 19 return 0;20 }
View code
B. muh and important things
Question: give you some tasks, each of which has a difficulty. Ask if you can sort these tasks by difficulty to discharge at least three different sequences.
Solution: If three or more tasks have the same difficulty, we can construct an answer, if there are no three tasks with the same difficulty and two groups of tasks with the same difficulty, an answer can be constructed. Otherwise, no solution is available.
Code:
1 #include <cstdio> 2 #include <cstring> 3 #include <set> 4 #include <algorithm> 5 using namespace std; 6 7 pair<int, int> a[2010]; 8 int o[3][2010], n; 9 10 void ot() {11 printf("YES\n");12 for(int i = 0; i < 3; i++) {13 for(int j = 0; j < n; j++) printf("%d%c", o[i][j], j == n - 1 ? ‘\n‘:‘ ‘);14 }15 }16 17 int main() {18 int k = 1;19 scanf("%d", &n);20 for(int i = 0; i < n; i++) {21 scanf("%d", &a[i].first);22 a[i].second = i + 1;23 }24 sort(a, a + n);25 for(int i = 0; i < n; i++) o[0][i] = o[1][i] = o[2][i] = a[i].second;26 for(int i = 0; i < n - 1; i++) {27 if(i + 2 < n && a[i].first == a[i + 1].first && a[i + 2].first == a[i + 1].first) {28 o[1][i] = a[i + 1].second, o[1][i + 1] = a[i].second;29 o[2][i] = a[i + 2].second, o[2][i + 2] = a[i].second;30 ot();31 return 0;32 } else if(a[i].first == a[i + 1].first){33 o[k][i] = a[i + 1].second, o[k][i + 1] = a[i].second;34 k++;35 if(k == 3) {36 ot();37 return 0;38 }39 }40 }41 printf("NO\n");42 43 return 0;44 }
View code
C. muh and House of Cards: Use a card to build a house. The number of rooms on the first floor is smaller than that on the second floor. The number of cards you are given now. For more information, see the figure. Solution: we can find that the number of cards required for each layer is 2 + 3 * k, and K is the number of houses-1. Then we can enumerate the layers and determine whether the requirements of the questions can be met. That is, K at the next layer should be at least k + 1 at the previous layer. For details, see the code. Code:
1 #include <cstdio> 2 #include <cstring> 3 #include <set> 4 #include <algorithm> 5 using namespace std; 6 7 pair<int, int> a[2010]; 8 int o[3][2010], n; 9 10 int main() {11 long long n, k = 1, l = 0;12 scanf("%I64d", &n);13 int ans = 0;14 for(;;k++) {15 long long m = n;16 m -= 2 * k;17 if(m % 3 != 0) { l += k; continue; }18 m /= 3;19 if(m >= l) ans++;20 else break;21 l += k;22 }23 printf("%d\n", ans);24 25 return 0;26 }
View code
Codeforces round #269 (Div. 2) Solution