100114D
这道题用暴力水过了,蒟蒻是这么想的:枚举两个端点,找最小值,因为shift只能用一次,但是这样10^9*2.5要t,所以减掉只有一个黑点的情况,然后复杂度变为10^9*0.6
#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;
int n,ll=-(<<),rr=-(<<),ans;
vector<int>left1;
vector<int>right1;
char c;
char s[];
int sum[];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
cin>>n;
int pos=;
cin.ignore();
for(int i=;i<=n;i++)
{
c=getchar();
s[i]=c;
sum[i]=sum[i-]+(c=='*');
}
s[]='.';
s[++n]='.';
for(int i=;i<=n;i++)
{
int l,r;
if(s[i]=='*'&&s[i-]=='.'){l=i;left1.push_back(i);}
if(s[i]=='*'&&s[i+]=='.')
{
r=i;
if(r-l+<)
{
left1.pop_back();
continue;
}
right1.push_back(i); }
}
int l=,r=;
int MAX=-(<<);
for(int i=;i<left1.size();i++)
{
for(int j=i;j<right1.size();j++)
{
int a=right1[j]-left1[i]+;
// cout<<"left:"<<left1[i]<<endl;
// cout<<"right:"<<right1[j]<<endl;
int b=sum[right1[j]]-sum[left1[i]-];//操作数a-b+2和b比较
// cout<<"MAX="<<MAX<<" "<<a<<" "<<b<<endl;
if(a-b+<b&&MAX<*b-a-)
{
MAX=*b-a-;
ll=left1[i];rr=right1[j];
}
}
}
// cout<<"ll="<<ll<<" "<<"rr="<<rr<<endl;
if(MAX!=-(<<))
{
ans+=(+rr-ll-*(sum[rr]-sum[ll-]));
}
ans+=sum[n-];
// cout<<sum[n]<<endl;
cout<<ans<<endl;
if(MAX!=-(<<))
{
cout<<ll<<endl;
cout<<"Shift+"<<rr<<endl;
for(int i=ll;i<=rr;i++)
if(s[i]=='.')
{
cout<<"Ctrl+"<<i<<endl;
}
}
if(ll==-(<<)&&rr==-(<<))
{
ll=;rr=;
}
for(int i=;i<ll;i++)
if(s[i]=='*')cout<<"Ctrl+"<<i<<endl;
for(int i=rr+;i<=n;i++)
if(s[i]=='*')cout<<"Ctrl+"<<i<<endl;
fclose(stdin);
fclose(stdout);
return ;
}
100114D的更多相关文章
随机推荐
- AC日记——字符环 openjudge 1.7 30
30:字符环 总时间限制: 1000ms 内存限制: 65536kB 描述 有两个由字符构成的环.请写一个程序,计算这两个字符环上最长连续公共字符串的长度.例如,字符串“ABCEFAGADEGKA ...
- CTF中那些脑洞大开的加密(1)
0x01 目录 各种文本加密 Shell 1 2 3 4 5 6 7 8 9 10 11 12 换位加密: 1.栅栏密码(Rail-fence Cipher) ...
- 关于ubuntu的sources.list总结
一.作用 文件/etc/apt/sources.list是一个普通可编辑的文本文件,保存了ubuntu软件更新的源服务器的地址.和sources.list功能一样的是/etc/apt/sources. ...
- linux下截取给定路径中的目录部分
在日常运维中,有时会要求截取一个路径中的目录部分.截取目录的方法,有以下两种:1)dirname命令(最常用的方法):用于取给定路径的目录部分.很少直接在shell命令行中使用,一般把它用在shell ...
- phantomjs模拟登录
最近在做一些公司其他部门系统的后台模拟操作,但由于那边的系统最开始是外包给其他公司开发的,现在那边的开发也不知道有些post的参数是如何生成的.于是想考察下是不是可以把phantomjs这个工具给加进 ...
- 使用gogs,drone搭建自动部署
使用gogs,drone搭建自动部署 使用gogs,drone,docker搭建自动部署测试环境 Gogs是一个使用go语言开发的自助git服务,支持所有平台Docker是使用go开发的开源容器引擎D ...
- node基础04:模块调用
1.模块调用 node遵循AMD规范 //server.js var http = require("http"); var Teacher = require("./t ...
- nginx图片处理相关
nginx本身有支持图片处理的模块,通过外部插件也可以实现此功能. libgd的安装 前提是要有libgd的库文件, (1)去官网访问主页没问题,下载文件还是FQ下的,为了方便大家提供一个链接:htt ...
- ORA-28000: the account is locked-的解决办法
ORA-28000: the account is locked第一步:使用PL/SQL,登录名为system,数据库名称不变,选择类型的时候把Normal修改为Sysdba;第二步:选择myjob, ...
- Use Dapper ORM With ASP.NET Core
Dapper.NET is not just another ORM tool, it's considered as the king of ORM. Because it's fast, easy ...