|Vijos|贪心|P1414 Dejected Birthday-盗窃
生活随笔
收集整理的这篇文章主要介绍了
|Vijos|贪心|P1414 Dejected Birthday-盗窃
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
https://vijos.org/p/1414
经典删数问题,英文内容为“给出一串数字删除n位后使值最小”,根据贪心思维,要删除Ai>Ai+1的每个Ai
注意前导0,以及全部为0时要保留一位0输出。
#include<cstdio> #include<cmath> #include<algorithm> #include<cstring> #define ms(i,j) memset(i,j,sizeof(i)); using namespace std; int num[255]; int main() {ms(num,0);int tot = -1;char ch = getchar();while (ch!='\n'){num[++tot] = ch - '0';ch = getchar();}int n;int len = tot;scanf("%d", &n);for (int i=0;i<n;i++){for (int j=0;j<=tot;j++){if (num[j]>num[j+1]){for (int k=j;k<tot;k++){num[k] = num[k+1];} len--;break;}}}int i = 0;while (num[i]==0&&i<=tot) i++;if (i>len) printf("%d", 0); elsefor (;i<=len;i++) printf("%d", num[i]);return 0; }
转载于:https://www.cnblogs.com/flyinthesky1/p/6384319.html
总结
以上是生活随笔为你收集整理的|Vijos|贪心|P1414 Dejected Birthday-盗窃的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 集成电路883和883b有什么区别
- 下一篇: codevs1127 接水问题