贪心 Codeforces Round #300 A Cutting Banner

题目传送门

 1 /*
 2     贪心水题:首先,最少的个数为n最大的一位数字mx,因为需要用1累加得到mx,
 3             接下来mx次循环,若是0,输出0;若是1,输出1,s[j]--;
 4     注意:之前的0的要忽略
 5 */
 6 #include <cstdio>
 7 #include <iostream>
 8 #include <cstring>
 9 #include <string>
10 #include <algorithm>
11 #include <cmath>
12 #include <set>
13 #include <map>
14 using namespace std;
15
16 const int MAXN = 1e4 + 10;
17 const int INF = 0x3f3f3f3f;
18
19 int main(void)        //Codeforces Round #300 A Cutting Banner
20 {
21     //freopen ("B.in", "r", stdin);
22
23     char s[10];
24     while (scanf ("%s", &s) == 1)
25     {
26         int len = strlen (s);
27         int mx = -1;
28         for (int i=0; i<len; ++i)    mx = max (mx, s[i] - ‘0‘);
29
30         printf ("%d\n", mx);
31         for (int i=1; i<=mx; ++i)
32         {
33             bool ok = false;
34             for (int j=0; j<len; ++j)
35             {
36                 if (s[j] == ‘0‘)
37                 {
38                     if (!ok)    continue;
39                     else    printf ("0");
40                 }
41                 else
42                 {
43                     ok = true;
44                     printf ("1");    s[j]--;
45                 }
46             }
47             if (i < mx)    printf (" ");
48         }
49         puts ("");
50     }
51
52     return 0;
53 }
时间: 2024-08-24 16:25:28

贪心 Codeforces Round #300 A Cutting Banner的相关文章

水题 Codeforces Round #300 A Cutting Banner

题目传送门 1 /* 2 水题:一开始看错题意,以为是任意切割,DFS来做:结果只是在中间切出一段来 3 判断是否余下的是 "CODEFORCES" :) 4 */ 5 #include <cstdio> 6 #include <iostream> 7 #include <cstring> 8 #include <string> 9 #include <algorithm> 10 #include <cmath>

Codeforces Round #300 (A,B,C,D)

题目传送:Codeforces Round #300 A. Cutting Banner 思路:一看题就会错意了,然后一顿猛敲,果不其然的被hack了,然后才发现只需要剪中间那一段就可以了,然后又傻逼得少写一个等号,还是被hack了,心累啊 AC代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cmath> #in

Codeforces Round #300——C贪心——Tourist&#39;s Notes

Description A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer hi. The tourist pick smooth enough route for his hike, me

Codeforces Round #300

A. Cutting Banner 关键字:[读题][字符串][枚举] 坑点:能不能只减去某一段字符串把剩下的按原来的顺序连起来组成"CODEFORCES",而减下一段"CODEFORCES"是不行的 e.g. "CODEFAAAAORCES"是可行的         而 "AACODEFORCESAA"是不可行的 B. Quasi Binary 题意:给出一个数n,求最少用几个形如"1010"这样只包含'

贪心 Codeforces Round #303 (Div. 2) B. Equidistant String

题目传送门 1 /* 2 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 3 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <cstring> 8 #include <cmath> 9 #include <iostream> 10 using namespace std; 11 12 const int MAX

贪心 Codeforces Round #191 (Div. 2) A. Flipping Game

题目传送门 1 /* 2 贪心:暴力贪心水水 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 using namespace std; 8 9 const int MAXN = 1e2 + 10; 10 const int INF = 0x3f3f3f3f; 11 int a[MAXN]; 12 13 int main(void) //Codeforces Round #191

贪心 Codeforces Round #301 (Div. 2) B. School Marks

题目传送门 1 /* 2 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 3 num1是输出的1的个数,numy是除此之外的数都为y,此时的numy是最少需要的,这样才可能中位数大于等于y 4 */ 5 #include <cstdio> 6 #include <iostream> 7 #include <algorithm> 8 #include <cstring> 9 using na

贪心 Codeforces Round #297 (Div. 2) C. Ilya and Sticks

题目传送门 1 /* 2 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 3 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <cstring> 8 #include <cmath> 9 using namespace std; 10 11 typedef long long ll; 12 13 co

贪心 Codeforces Round #135 (Div. 2) C. Color Stripe

题目传送门 1 /* 2 贪心:当m == 2时,结果肯定是ABABAB或BABABA,取最小改变量:当m > 2时,当与前一个相等时, 改变一个字母 3 同时不和下一个相等就是最优的解法 4 */ 5 #include <cstdio> 6 #include <cstring> 7 #include <algorithm> 8 using namespace std; 9 10 const int MAXN = 5e5 + 10; 11 const int IN