标签:for getch stdin 复杂 ace include 情况 har nbsp
这道题用暴力水过了,蒟蒻是这么想的:枚举两个端点,找最小值,因为shift只能用一次,但是这样10^9*2.5要t,所以减掉只有一个黑点的情况,然后复杂度变为10^9*0.6
#include<iostream> #include<vector> #include<cstdio> using namespace std; int n,ll=-(1<<29),rr=-(1<<29),ans; vector<int>left1; vector<int>right1; char c; char s[100010]; int sum[1000010]; int main() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); cin>>n; int pos=0; cin.ignore(); for(int i=1;i<=n;i++) { c=getchar(); s[i]=c; sum[i]=sum[i-1]+(c==‘*‘); } s[0]=‘.‘; s[++n]=‘.‘; for(int i=1;i<=n;i++) { int l,r; if(s[i]==‘*‘&&s[i-1]==‘.‘){l=i;left1.push_back(i);} if(s[i]==‘*‘&&s[i+1]==‘.‘) { r=i; if(r-l+1<2) { left1.pop_back(); continue; } right1.push_back(i); } } int l=0,r=0; int MAX=-(1<<29); for(int i=0;i<left1.size();i++) { for(int j=i;j<right1.size();j++) { int a=right1[j]-left1[i]+1; // cout<<"left:"<<left1[i]<<endl; // cout<<"right:"<<right1[j]<<endl; int b=sum[right1[j]]-sum[left1[i]-1];//操作数a-b+2和b比较 // cout<<"MAX="<<MAX<<" "<<a<<" "<<b<<endl; if(a-b+2<b&&MAX<2*b-a-2) { MAX=2*b-a-2; ll=left1[i];rr=right1[j]; } } } // cout<<"ll="<<ll<<" "<<"rr="<<rr<<endl; if(MAX!=-(1<<29)) { ans+=(3+rr-ll-2*(sum[rr]-sum[ll-1])); } ans+=sum[n-1]; // cout<<sum[n]<<endl; cout<<ans<<endl; if(MAX!=-(1<<29)) { cout<<ll<<endl; cout<<"Shift+"<<rr<<endl; for(int i=ll;i<=rr;i++) if(s[i]==‘.‘) { cout<<"Ctrl+"<<i<<endl; } } if(ll==-(1<<29)&&rr==-(1<<29)) { ll=1;rr=0; } for(int i=1;i<ll;i++) if(s[i]==‘*‘)cout<<"Ctrl+"<<i<<endl; for(int i=rr+1;i<=n;i++) if(s[i]==‘*‘)cout<<"Ctrl+"<<i<<endl; fclose(stdin); fclose(stdout); return 0; }
标签:for getch stdin 复杂 ace include 情况 har nbsp
原文地址:http://www.cnblogs.com/19992147orz/p/6009681.html