标签:style blog http color io os ar for sp
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 }
题意:给你一些任务,每个任务有一个难度。问你这些任务按照难度排序能否排出至少3个不同的序列。
解法:显然若有3个或以上任务难度相同我们就可以构造出答案,若没有3个任务难度相同有两组2个难度相同的任务也可构造出答案,否则无解。
代码:
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 }
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 }
Codeforces Round #269 (Div. 2) solution
标签:style blog http color io os ar for sp
原文地址:http://www.cnblogs.com/shiina-mashiro/p/4000029.html