zoj3829 Known Notation --- 2014 ACM-ICPC Asia Mudanjiang Regional Contest
2015-09-23 19:40
495 查看
根据规则,可以发现,一*之前必须有至少2数字。一(11*)这反过来可以被视为一数字。
因此,总位数必须大于*号码,或者你会加入数字。
添加数字后,,为了确保该解决方案将能够获得通过交流。那么肯定是*放回去,图提出。交易所至今资格。
因此,总位数必须大于*号码,或者你会加入数字。
添加数字后,,为了确保该解决方案将能够获得通过交流。那么肯定是*放回去,图提出。交易所至今资格。
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; char s[1010]; int len,ans,opp[1010],num[1010],op,cnt; bool check(int b) { int a=0; for(int i=0;i<len;i++) { if(s[i]=='*') a++; else b++; if(a>=b) return 0; } return 1; } int main() { int T,i,j,b; scanf("%d",&T); while(T--) { scanf("%s",s); len=strlen(s); cnt=op=ans=0; for(i=0;i<len;i++) { if(s[i]=='*') opp[op++]=i; else num[cnt++]=i; } if(op==0) { puts("0"); continue; } for(i=0,j=cnt-1;i<j;i++,j--) swap(num[i],num[j]); if(op>=cnt) ans+=(op-cnt+1); int fir=0,last=0; b=ans; while(!check(b)) { ans++; swap(s[opp[fir++]],s[num[last++]]); } printf("%d\n",ans); } return 0; }
相关文章推荐
- Linux 磁阵性能瓶颈定位过程
- javascript模拟getElementByClassName
- Android设计支持库(Android Design Support Library)
- 实现一个工具类,可以把HBase任意表的任意多的列导出到任意指定的HDFS中
- VS2010+WDK配置要点
- LeetCode(53) Climbing Stairs (剑指Offer->跳台阶、变态跳台阶)
- 数独设计(2)
- Number Sequence
- The Water Problem hdoj 5443 (排序)
- HDU 5464 Clarke and problem(dp 动态规划)——BestCoder Round #56(div.1 div.2)
- strcpy
- javascript自学之路(二)————js对象类型之宿主对象
- 重载二维数组下标"[][]"
- LEETCODE-Merge Two Sorted Lists
- ToastUtils 对系统Toast的封装
- js onsubmit
- 一个人的成功不是没有理由的!(人物之楼天城)
- UVA - 1225 Digit Counting
- 最小生成树详解
- 图片格式