ZOJ 3829 2014牡丹江K 贪心
2014-10-14 12:59
302 查看
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5383
1.全是数字的话合法
2.最后一个字符在不满足1的时候必须是*
3.如果数字的个数num-1<op(*个数)的话,一定是在最前方增加op-(num-1)个数字
4.从左向右扫描,记录仍可使用的数字个数cnt,碰到数字cnt++,碰到*判断cnt数目是否小于2,如果小于2的话,最好的操作肯定是把他交换到最右侧的数字。
1.全是数字的话合法
2.最后一个字符在不满足1的时候必须是*
3.如果数字的个数num-1<op(*个数)的话,一定是在最前方增加op-(num-1)个数字
4.从左向右扫描,记录仍可使用的数字个数cnt,碰到数字cnt++,碰到*判断cnt数目是否小于2,如果小于2的话,最好的操作肯定是把他交换到最右侧的数字。
#include<stdio.h> #include<string.h> char str[11111]; int main(){ int t; scanf("%d",&t); while(t--){ scanf("%s",&str); int len=strlen(str); int a=0,b=0; for(int i=0;i<len;i++){ if(str[i]=='*')a++; else b++; } int ans=0,cnt=0; if(b-1<a){ ans+=a-(b-1); cnt+=a-(b-1); } if(str[len-1]!='*'){ for(int i=0;i<len;i++){ if(str[i]=='*'){ str[len-1]='*',str[i]='1',ans++; break; } } } for(int i=0;i<len;i++){ if(str[i]=='*'){ if(cnt<2){ for(int j=len-1;j>i;j--){ if(str[j]!='*'){ str[j]='*',str[i]='1',ans++,cnt++; break; } } }else cnt=cnt-1; }else cnt++; } printf("%d\n",ans); } return 0; }
相关文章推荐
- ZOJ 3829 Known Notation / 2014牡丹江区域赛 K (模拟, 贪心)
- zoj 3829 Known Notation(2014在牡丹江区域赛k称号)
- ZOJ 3829 (2014 牡丹江现场赛 K 题)
- zoj 3829 Known Notation The 2014 ACM-ICPC Asia Mudanjiang Regional Contest K 贪心
- ZOJ 3820 Building Fire Stations (二分+贪心) 2014 牡丹江现场赛B
- ZOJ 3829 Known Notation (2014牡丹江H称号)
- zoj 3829 (2014牡丹江区域赛K) Known Notation
- ZOJ 3829 Known Notation (2014牡丹江H题)
- ACM学习历程——ZOJ 3829 Known Notation (2014牡丹江区域赛K题)(策略,栈)
- zoj 3829 Known Notation (The 2014 ACM-ICPC Asia Mudanjiang Regional Contest K题) 贪心
- zoj 3811 (2014 牡丹江网赛 C) Untrusted Patrol
- [ACM] zoj 3809 The Himalayas (2014 ACMICPC Regional 牡丹江站网络赛 A题)
- [zoj 3822]2014牡丹江区域赛 Domination 概率dp求期望
- 贪心+模拟 ZOJ 3829 Known Notation
- ZOJ3819 ACM-ICPC 2014 亚洲区域赛牡丹江赛区现场赛A题 Average Score 签到题
- ACM学习历程——ZOJ 3822 Domination (2014牡丹江区域赛 D题)(概率,数学递推)
- ZOJ 3829 模拟贪心
- K - Known Notation ZOJ - 3829 贪心
- ZOJ 3809 The Himalayas (2014 ACM/ICPC 牡丹江站 网络预选赛 A 题)
- ZOJ 3826 Hierarchical Notation(2014 牡丹江 H,字符串模拟)