标签:没有 cout codeforce 奇数 ble while def .com color
题解:~~~没啥说的,没有pearls也算YES!!!
1 #pragma warning(disable:4996) 2 #include<map> 3 #include<string> 4 #include<cstdio> 5 #include<cstring> 6 #include<iostream> 7 #include<algorithm> 8 using namespace std; 9 #define ll long long 10 11 const int maxn = 200005; 12 13 string s; 14 15 int main() 16 { 17 while (cin >> s) { 18 int n = s.size(); 19 int x = 0, y = 0; 20 for (int i = 0; i < n; i++) if (s[i] == ‘o‘) x++; 21 for (int i = 0; i < n; i++) if (s[i] == ‘-‘) y++; 22 if (x == 0) printf("YES\n"); 23 else { 24 if (y % x == 0) printf("YES\n"); 25 else printf("NO\n"); 26 } 27 28 } 29 return 0; 30 }
题解:k是偶数,好办。k是奇数,分类讨论,如果k<=n-2,放在中间。如果k>n-2,第三排第1个位置和第n-2个位置放上‘#’(0到n-1)。至于为啥子,拿笔画一下就明白了。
1 #pragma warning(disable:4996) 2 #include<map> 3 #include<string> 4 #include<cstdio> 5 #include<cstring> 6 #include<iostream> 7 #include<algorithm> 8 using namespace std; 9 #define ll long long 10 11 const int maxn = 200005; 12 13 int n, k; 14 15 int main() 16 { 17 while (cin >> n >> k) { 18 if (k % 2 == 0) { 19 printf("YES\n"); 20 for (int i = 0; i < n; i++) printf("."); 21 printf("\n"); 22 for (int i = 0; i < n; i++) { 23 if (1 <= i && i <= k / 2) printf("#"); 24 else printf("."); 25 } 26 printf("\n"); 27 for (int i = 0; i < n; i++) { 28 if (1 <= i && i <= k / 2) printf("#"); 29 else printf("."); 30 } 31 printf("\n"); 32 for (int i = 0; i < n; i++) printf("."); 33 printf("\n"); 34 } 35 else { 36 37 if (k <= n - 2) { 38 printf("YES\n"); 39 for (int i = 0; i < n; i++) printf("."); 40 printf("\n"); 41 for (int i = 0; i < n; i++) { 42 int pos = n / 2; 43 int l = pos - k / 2; 44 int r = l + k - 1; 45 if (l <= i && i <= r) printf("#"); 46 else printf("."); 47 } 48 printf("\n"); 49 for (int i = 0; i < n; i++) printf("."); 50 printf("\n"); 51 for (int i = 0; i < n; i++) printf("."); 52 printf("\n"); 53 } 54 else { 55 printf("YES\n"); 56 int t = k - (n - 2); 57 for (int i = 0; i < n; i++) printf("."); 58 printf("\n"); 59 for (int i = 0; i < n; i++) { 60 if (1 <= i && i <= n - 2) printf("#"); 61 else printf("."); 62 } 63 printf("\n"); 64 for (int i = 0; i < n; i++) { 65 if (1 <= i && i <= t - 1) printf("#"); 66 else if (i == n - 2) printf("#"); 67 else printf("."); 68 } 69 printf("\n"); 70 for (int i = 0; i < n; i++) printf("."); 71 printf("\n"); 72 73 } 74 } 75 } 76 return 0; 77 }
题解:想象一个轴,上面有256个点(0~255),如果当前的点没被染色,则往前找第一个颜色号小于a[i]-k+1的点,然后对这段区间重新染色。
1 #pragma warning(disable:4996) 2 #include<map> 3 #include<string> 4 #include<cstdio> 5 #include<cstring> 6 #include<iostream> 7 #include<algorithm> 8 using namespace std; 9 #define ll long long 10 11 const int maxn = 100005; 12 13 int n, k; 14 int color[300]; 15 bool use[300]; 16 17 int main() 18 { 19 while (scanf("%d%d", &n, &k) != EOF) { 20 memset(use, 0, sizeof(use)); 21 for (int i = 0; i < 256; i++) color[i] = i; 22 while (n--) { 23 int tp; 24 scanf("%d", &tp); 25 int ep = tp; 26 if (!use[tp]) { 27 while (ep >= 0 && color[ep] >= tp - k + 1) ep--; //找第一个颜色小于tp-k+1的点 28 for (int i = ep + 1; i <= tp; i++) { //重新染色 29 use[i] = true; 30 color[i] = color[ep + 1]; 31 } 32 } 33 cout << color[tp] << " "; 34 } 35 } 36 return 0; 37 }
Codeforces Round #480 (Div. 2)
标签:没有 cout codeforce 奇数 ble while def .com color
原文地址:https://www.cnblogs.com/zgglj-com/p/9017381.html