HNU 12870 Selection
来源:互联网 发布:易酷cms官网 编辑:程序博客网 时间:2024/05/22 06:45
题意:
给你一串字符串,每个字符表示一个文件,其中*表示我们要选取的文件,.表示不要选取的文件
选取文件时可使用一个Shift,可使用多次Ctrl,且Shift不能和Ctrl同时使用
方法:
我之前一直是用数组去记录连续的*有多少且记录该段*的左区间,发现这么写都写不对。。。。
后面LCB告诉我直接用求最大连续子序列和的方法做就可以了。。。
代码:
#include <cstdio>#include <cstring>#define maxn 100005char ch[maxn];int sum[maxn];int pos[maxn];int main(){ int n; while(scanf("%d",&n)!=EOF) { scanf("%s",ch+1); int max= 0; memset(sum, 0, sizeof(sum)); int j; int ans= 0; for(int i= 1; i<= n; i++) {if(sum[i-1]> 0)sum[i]+= sum[i-1], pos[i]= pos[i-1];elsepos[i]= i;if(ch[i]=='*')sum[i]++, ans++;elsesum[i]--;if(sum[i]> max){max= sum[i];j= i;} }if(max<= 2){printf("%d\n",ans);int flag= 1;for(int i= 1; i<= n; i++)if(ch[i]=='*'){if(flag== 1){printf("%d\n",i);flag= 0;}elseprintf("Ctrl+%d\n",i);}}else{printf("%d\n",ans-max+2);printf("%d\nShift+%d\n",pos[j],j);for(int i= 1; i<= n; i++)if(ch[i]=='*'){if(i< pos[j]|| i> j)printf("Ctrl+%d\n",i);}else if(ch[i]=='.' && i>= pos[j] && i<= j)printf("Ctrl+%d\n",i);} }return 0;}
0 0
- HNU 12870 Selection
- Selection
- Selection
- :: selection
- HNU 11877
- hnu 病毒
- hnu 12948
- HNU Profits
- HNU 21
- acm hnu 10136 Palindromes
- hnu 12029 LCA问题
- hnu 12439 #贪心
- [讨论]hnu 12450 Painting
- hnu-City Merger
- hnu-Kitchen Robot
- HNU 12813 Restore Calculation
- HNU 12834 Thread Tree
- acm HNU Dwarf Tower
- CA认证原理以及实现(下)
- 日记
- Excel导出学习之道:Java Web利用POI导出Excel简单例子
- work_weipa_viewpager
- 好弱的csdn
- HNU 12870 Selection
- 【ThinkingInC++】10、全局变量的使用
- hdu 4821 字符串hash+map判重 String (长春市赛区I题)
- C++ 之 虚函数、纯虚函数
- poj1047
- 日志类
- UNIX网络编程笔记一
- 系统提供的头文件被不小心修改的修正步骤
- hdu -- 3336 Count the string(KMP + dp)