cf C. George and Number

http://codeforces.com/problemset/problem/387/C

题意:给你一个大数,让你求个集合,可以通过操作得到这个数,求集合中个数最大值,操作 :从集合中任意取两个数,大的数放在前面小的数放在后面组成一个数在重新放入集合中,经过重复的操作,集合中只剩一个数,这个数就是给你的数。

思路:要求个数最大,可以让这个大数的每一个数字为集合中的一个数,但是集合中不能有0,所以在连续的0前面要连着一个非零的数。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 using namespace std;
 5
 6 char str[1000000];
 7
 8 int main()
 9 {
10     while(scanf("%s",str)!=EOF)
11     {
12         int k=strlen(str);
13         int ans=0;
14         for(int i=k-1; i>=0; i--)
15         {
16              int j=i;
17              while(str[i]==‘0‘) i--;
18              if(j-i+1<i) ans++;
19              else if(j-i+1==i)
20              {
21                  bool flag=false;
22                  for(int k=0; k<i; k++)
23                  {
24                      if(str[k]>str[k+i]&&str[k]!=str[k+i])
25                      {
26                          flag=true;
27                          ans++;
28                          break;
29                      }
30                      else if(str[k]<str[k+i]&&str[k]!=str[k+i])
31                      {
32                           ans++;
33                           i=0;
34                           flag=true;
35                           break;
36                      }
37                  }
38                  if(!flag) ans++;
39              }
40              else if(j-i+1>i)
41              {
42                  i=0;
43                  ans++;
44              }
45         }
46         printf("%d\n",ans);
47     }
48     return 0;
49 }

时间: 2024-08-04 03:44:22

cf C. George and Number的相关文章

CF 546D Soldier and Number Game

Describe Two soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the second soldier. Then the second one tries to make maximum possible number of rounds. Each round consists of choosing a positive

CF 441E Valera and Number

CF 441E Description 一共执行\(k\)次,每次有\(p\%\)把\(x * 2\),有\((100 - p)\%\)把\(x + 1\).问二进制下\(x\)末尾期望\(0\)的个数. Solution 设\(f[i][j]\)为执行第\(i\)次后\(x + j\)末尾期望\(0\)的个数 加一:$f[i + 1][j - 1] = f[i + 1][j - 1] + (100 - p)% * f[i][j]; $ 乘二:\(f[i + 1][j * 2] = f[i +

CF 1215 B The Number of Products(思维题)

链接:https://codeforces.com/contest/1215/problem/B You are given a sequence a1,a2,…,ana1,a2,…,an consisting of nn non-zero integers (i.e. ai≠0ai≠0). You have to calculate two following values: the number of pairs of indices (l,r)(l,r) (l≤r)(l≤r) such t

cf B Very Beautiful Number

题意:给你两个数p和x,然后让你找出一个长度为p的数,把它的最后移到最前面之后得到的数是原来数字的x倍,有很多这样的数取最小. 思路:枚举最后一位,然后就可以推出整个的一个数,然后比较得到的数的第一个数字和枚举的数字是否相等既可以. 1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <algorithm> 5 using namespace std; 6 7 int

cf D George and Interesting Graph

题意:给你一个有趣图的定义:在这个图中有一个根,根与每个点都有边和回边,除了根之外,其他的点的出度和入度都为2,然后给你一个图让你经过几步操作可以使此图变为有趣图,操作为:删边或者加边. 思路:枚举根,然后删除与根有关的边,重新建图,用二分图求最大匹配,可以用匈牙利算法,加的边数:满足题中有关根的加边数+(点数-匹配数),删掉的边数:边数-满足题中有关根的使用的边数-匹配时使用的边数. 1 #include <cstdio> 2 #include <cstring> 3 #incl

Codeforces Round #227 (Div. 2) / 387C George and Number (贪心)

链接:here~~~ 分割最多的数,使得分割的数连接在一起,得到原来的数,(分割的数大的放前面,两个数合并 比较此数大于后面的数,否则合并成一个数,不能分割,0不能单独存在) #include<iostream> using namespace std; int main() { string s; int i , j , ans = 0; cin >> s; for( i = 0; s[i] ;i = j) { for(j = i + 1 ; s[j] == '0';j ++);

cf B George and Round

题意:输入n,m,下一行为n个数a1<a2<a3......<an:然后再输入m个数b1<=b2<=b3<.....<=bm: 每个ai都必须在b中找到相等的数,找不到可以让比ai的大的数转化为ai,问最少需要添加几个数,使得ai在b都能找到相等的数. 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5

cf B George and Cards

题意:给你一个只有‘.’和'#'的n*n的格子,问所有的'#'是不是只属于一个十字叉,如果不是输出NO,否则输出YES. 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 6 int n; 7 char g[200][200]; 8 bool vis[200][200]; 9 10 int main() 11 { 12 scanf("

【Leetcode】17、Letter Combinations of a Phone Number

题目 Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letter