E

题目链接:https://vjudge.net/contest/168648#problem/E

题目大意:用最少的数字(全由0和1组成的数字)来凑成n

题解:啊,对于每一位,由于最多减1,所以最少一定是每一位的最大值,比如213,则必须3次,才能把个位变成0

有这个想法之后,就不难做了,我们直接减1就了,当为0 的时候,就不减了

注意前导0的问题

code:

#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main()
{
 string str,str1,str2;
 cin>>str;
 for(int i=0;i<str.size();i++)
 {
  for(int j=i+1;j<str.size();j++)
  {
   str1=str.substr(0,i)+str.substr(j);
   if(str1=="CODEFORCES")
   {
    printf("YES ");
    return 0;
   }
  }
 }
 printf("NO ");
 return 0;
}

原文地址:https://www.cnblogs.com/DemonZiv/p/7105421.html